When using MySQL C APIs in Linux, You need to introduce relevant libraries and include the header file mysql. h. MySQL provides a mysql_config script that can be used to obtain the parameters during compilation.
For example, execute mysql_config -- cflags in my RHEL 5.4X-64 to get the following information:
# 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-Buffers = 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
Therefore, you can add $ (mysql_config -- cflags) $ (mysql_config -- libs) to obtain the corresponding compilation parameters and libraries when compiling the code that requires MySQL c api. For example:
Gcc-W-Wall $ (mysql_config -- cflags) test_db_conn.c $ (mysql_config -- libs)-o test_db