参照《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