MySQL distributions contain amysqlclient.pc file that provides information about MySQL configuration for use by thepkg-config command. This enablespkg-config to be used as an alternative tomysql_config for obtaining information such as compiler flags or link libraries required to compile MySQL applications. For example, the following pairs of commands are equivalent:
mysql_config --cflagspkg-config --cflags mysqlclientmysql_config --libspkg-config --libs mysqlclientThe lastpkg-config command produces flags for dynamic linking. To produce flags for static linking, use this command:
pkg-config --static --libs mysqlclient On some platforms, the output with and without--static might be the same.
Ifpkg-config does not find MySQL information, it might be necessary to set thePKG_CONFIG_PATH environment variable to the directory in which themysqlclient.pc file is located, which by default is usually thepkgconfig directory under the MySQL library directory. For example (adjust the location appropriately):
# For sh, bash, ...export PKG_CONFIG_PATH=/usr/local/mysql/lib/pkgconfig# For csh, tcsh, ...setenv PKG_CONFIG_PATH /usr/local/mysql/lib/pkgconfig Themysqlconfig.pc installation location can be controlled using theINSTALL_PKGCONFIGDIRCMake option. SeeMySQL Source-Configuration Options.
The--variable option takes a configuration variable name and displays the variable value:
# installation prefix directorypkg-config --variable=prefix mysqlclient# header file directorypkg-config --variable=includedir mysqlclient# library directorypkg-config --variable=libdir mysqlclient To see which variable valuespkg-config can display using the--variable option, use this command:
pkg-config --print-variables mysqlclientYou can usepkg-config within a command line using backticks to include the output that it produces for particular options. For example, to compile and link a MySQL client program, usepkg-config as follows:
gcc -c `pkg-config --cflags mysqlclient` progname.cgcc -o progname progname.o `pkg-config --libs mysqlclient`