參照《Beginning Linux Programming》上的例程寫了一個鏈接mysql的c語言小程序connect1.c。可是按照書上的編譯命令沒法編譯。而後通過查閱資料解決了問題。記錄以下:mysql
首先書上的編譯命令是:web
gcc -I /usr/local/mysql/include/ connect1.c -L /usr/local/mysql/lib/ -l mysqlclient -o connect1
編譯不成功,始終提示directory not found。網上有人說編譯器不能識別全路徑制定的lib庫什麼的,衆說紛紜。後來我嘗試調換了一下命令各參數的順序:sql
gcc -I /usr/local/mysql/include/ -L /usr/local/mysql/lib/ connect1.c -o connect1 -lmysqlclient
媽蛋就成功了。編譯成功,沒法運行,提示不能加載mysql庫,這好像是mysql安裝包的問題,就是安裝沒成功,編譯器找不到對應的庫。小程序
dyld: Library not loaded: libmysqlclient.18.dylib Referenced from: /Users/tmxu/Projects/BeginningLinuxProgramming/./connect1 Reason: image not found Trace/BPT trap: 5
我參照了這個博客的解決方案http://www.blog.bridgeutopiaweb.com/post/how-to-fix-mysql-load-issues-on-mac-os-x/ide
評論第一樓的解決方案好評最高,因而執行一下,個人問題也解決了。post
Thank you for sharing ideas about this problem! For me none of the things above worked, unfortunately. However, I simply added a softlink from the standard MAC OS X dyld-library-path (/usr/lib/) to the libmysqlclient.18.dylib... so it can be found easily without changing much of the system. Maybe a good install process of MySQL should have done that automatically.
Here is the command:this
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib