在linux下面使用mysql的c api时需要引入相关的库并包含头文件mysql.h。mysql提供了一个mysql_config脚本,可以通过这个脚本获得编
在linux下面使用mysql的c api时需要引入相关的库并包含头文件mysql.h。mysql提供了一个mysql_config脚本,可以通过这个脚本获得编译时的参数.
如,在我的rhel 5.4x-64 中执行mysql_config --cflags可得:
#mysql_config --cflags
-i/usr/include/mysql -g -pipe -wp,-d_fortify_source=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -d_gnu_source -d_file_offset_bits=64 -d_largefile_source -fno-strict-aliasing -fwrapv
#mysql_config --libs
-rdynamic -l/usr/lib64/mysql -lmysqlclient -lz -lcrypt -lnsl -lm -l/usr/lib64 -lssl -lcrypto
于是,,在编译需要mysql c api的代码时可以加上 $(mysql_config --cflags) $(mysql_config --libs)来获得相应编译参数和库。如:
gcc -w -wall $(mysql_config --cflags) test_db_conn.c $(mysql_config --libs) -o test_db
