22.9.17. Building Client Programs

If you compile MySQL clients that you've written yourself or that you obtain from a third-party, they must be linked using the -lmysqlclient -lz options in the link command. You may also need to specify a -L option to tell the linker where to find the library. For example, if the library is installed in /usr/local/mysql/lib, use -L/usr/local/mysql/lib -lmysqlclient -lz in the link command.

For clients that use MySQL header files, you may need to specify an -I option when you compile them (for example, -I/usr/local/mysql/include), so that the compiler can find the header files.

Compiling MySQL Clients on Unix

To make it simpler to compile MySQL programs on Unix, we have provided the mysql_config script for you. See Section 4.7.2, “mysql_config — Get Compile Options for Compiling Clients”.

You can use it to compile a MySQL client as follows:

CFG=/usr/local/mysql/bin/mysql_config
sh -c "gcc -o progname `$CFG --cflags` progname.c `$CFG --libs`"

The sh -c is needed to get the shell not to treat the output from mysql_config as one word.

Compiling MySQL Clients on Microsoft Windows

On Windows, you can link your code with either the dynamic or static client library. The static library is named mysqlclient and the dynamic library is named libmysql.

If you link with the static library, failure can occur if certain conditions are not satisfied:

  • The client application must be compiled with exactly the same version of Visual Studio as that used to compile the library.

  • The client application should link the C runtime statically by using the /MT compiler option.

If the client application is built in in debug mode and uses the static debug C runtime (/MTd compiler option), it can link the mysqlclient if that library was built using the same option. If the client application uses the dynamic C runtime (/MD option, or /MDd option in debug mode), it cannot link with the static client library and must use the dynnamic library.

The MSDN page describing the link options can be found here: http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx

Copyright © 2010-2024 Platon Technologies, s.r.o.           Home | Man pages | tLDP | Documents | Utilities | About
Design by styleshout