Requirements
* mysql: MySQL client programs and shared library
* mysqlclient: Backlevel MySQL shared libraries (old libs)
* mysql-devel: Files for development of MySQL applications (a must have)
* mysql-server: Mysql server itself
* gcc, make and other development libs: GNU C compiler
# yum install mysql mysql-server
由于在之前安装mysql的时候没有安装mysql-devel,在编译是出现了找不到mysql.h的错误提示,fedora 12下再执行下面语句,重启mysql就可以搞定
# yum install mysql-devel
# service mysqld restart
在MySQL中有一个名叫mysql_config的特殊脚本,它将提供一些在编译时有用的信息,下面将介绍2个重要的选项:
--libs, 链接函数库
$ mysql_config --libs
输出:
-rdynamic -L/usr/lib/mysql -lmysqlclient -lz -lcrypt -lnsl -lm -lssl -lcrypto
--cflags, 寻找待编译文件中头文件的位置,以及其他重要的编译标志
$ mysql_config --cflags
输出:
-I/usr/include/mysql -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -fasynchronous-unwind-tables -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC -DUNIV_LINUX
编译:
gcc -o output-file $(mysql_config --cflags) mysql-c-api.c $(mysql_config --libs)
运行:
./output-file
参考链接:http://www.cyberciti.biz/tips/linux-unix-connect-mysql-c-api-program.html