Building and Running C API Client Programs
2133
• 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 to the
mysqlclient.lib
static library 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
must must be linked to the
libmysql.dll
dynamic library. It cannot link to the static client library.
The MSDN page describing the link options can be found here:
http://msdn.microsoft.com/en-us/
library/2kzt1wy3.aspx
Troubleshooting Problems Linking to the MySQL Client Library
Linking with the single-threaded library (
libmysqlclient
) may lead to linker errors related
to
pthread
symbols. When using the single-threaded library, please compile your client with
MYSQL_CLIENT_NO_THREADS
defined. This can be done on the command line by using the
-D
option
to the compiler, or in your source code before including the MySQL header files. This define should not
be used when building for use with the thread-safe client library (
libmysqlclient_r
).
If the linker cannot find the MySQL client library, you might get undefined-reference errors for symbols
that start with
mysql_
, such as those shown here:
/tmp/ccFKsdPa.o: In function `main':
/tmp/ccFKsdPa.o(.text+0xb): undefined reference to `mysql_init'
/tmp/ccFKsdPa.o(.text+0x31): undefined reference to `mysql_real_connect'
/tmp/ccFKsdPa.o(.text+0x69): undefined reference to `mysql_error'
/tmp/ccFKsdPa.o(.text+0x9a): undefined reference to `mysql_close'
You should be able to solve this problem by adding
-Ldir_path -lmysqlclient
at the end of your
link command, where
dir_path
represents the path name of the directory where the client library is
located. To determine the correct directory, try this command:
shell>
mysql_config --libs
The output from
mysql_config
might indicate other libraries that should be specified on the link
command as well. You can include
mysql_config
output directly in your compile or link command
using backticks. For example:
shell>
gcc -o progname progname.o `mysql_config --libs`
If an error occurs at link time that the
floor
symbol is undefined, link to the math library by adding
-lm
to the end of the compile/link line.
If you get
undefined reference
errors for the
uncompress
or
compress
function, add
-lz
to the
end of your link command and try again.
Similarly, if you get undefined-reference errors for other functions that should exist on your system,
such as
connect()
, check the manual page for the function in question to determine which libraries
you should add to the link command.
If you get undefined-reference errors such as the following for functions that don't exist on your system,
it usually means that your MySQL client library was compiled on a system that is not 100% compatible
with yours:
mf_format.o(.text+0x201): undefined reference to `__lxstat'
In this case, you should download the latest MySQL or MySQL Connector/C source distribution and
compile the MySQL client library yourself. See
Section 2.17, “Installing MySQL from Source”
, and
Section 20.4, “MySQL Connector/C”
.
20.6.3.2. Writing C API Threaded Client Programs
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...