Documentation Home
MySQL 5.7 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 37.4Mb
PDF (A4) - 37.4Mb
PDF (RPM) - 36.9Mb
EPUB - 10.6Mb
HTML Download (TGZ) - 10.3Mb
HTML Download (Zip) - 10.4Mb
HTML Download (RPM) - 9.0Mb
Eclipse Doc Plugin (TGZ) - 11.2Mb
Eclipse Doc Plugin (Zip) - 13.4Mb
Man Pages (TGZ) - 204.7Kb
Man Pages (Zip) - 311.7Kb
Info (Gzip) - 3.4Mb
Info (Zip) - 3.4Mb
Excerpts from this Manual

MySQL 5.7 Reference Manual  /  ...  /  Building C API Client Programs Using pkg-config

26.8.4.2 Building C API Client Programs Using pkg-config

As of MySQL 5.7.9, MySQL distributions contain a mysqlclient.pc file that provides information about MySQL configuration for use by the pkg-config command. This enables pkg-config to be used as an alternative to mysql_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 --cflags
pkg-config --cflags mysqlclient

mysql_config --libs
pkg-config --libs mysqlclient

The last pkg-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.

Note

If pkg-config does not find MySQL information, it might be necessary to set the PKG_CONFIG_PATH environment variable to the directory in which the mysqlclient.pc file is located, which by default is usually the pkgconfig directory under the MySQL library directory. For example (adjust the location appropriately):

export PKG_CONFIG_PATH=/usr/local/mysql/lib/pkgconfig # sh, bash, ...
setenv PKG_CONFIG_PATH /usr/local/mysql/lib/pkgconfig # csh, tcsh, ...

The mysqlconfig.pc installation location can be controlled using the INSTALL_PKGCONFIGDIR CMake option. See Section 2.9.4, “MySQL Source-Configuration Options”.

The --variable option takes a configuration variable name and displays the variable value:

pkg-config --variable=prefix mysqlclient     # installation prefix directory
pkg-config --variable=includedir mysqlclient # header file directory
pkg-config --variable=libdir mysqlclient     # library directory

To see which variable values pkg-config can display using the --variable option, use this command:

pkg-config --print-variables mysqlclient

You can use pkg-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, use pkg-config as follows:

gcc -c `pkg-config --cflags mysqlclient` progname.c
gcc -o progname progname.o `pkg-config --libs mysqlclient`

User Comments
Sign Up Login You must be logged in to post a comment.