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
Содержание 5.0
Страница 1: ...MySQL 5 0 Reference Manual ...
Страница 18: ...xviii ...
Страница 60: ...40 ...
Страница 396: ...376 ...
Страница 578: ...558 ...
Страница 636: ...616 ...
Страница 844: ...824 ...
Страница 1234: ...1214 ...
Страница 1426: ...MySQL Proxy Scripting 1406 The following diagram shows an overview of the classes exposed by MySQL Proxy ...
Страница 1427: ...MySQL Proxy Scripting 1407 ...
Страница 1734: ...1714 ...
Страница 1752: ...1732 ...
Страница 1783: ...Configuring Connector ODBC 1763 ...
Страница 1793: ...Connector ODBC Examples 1773 ...
Страница 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Страница 1842: ...Connector Net Installation 1822 5 Once the installation has been completed click Finish to exit the installer ...
Страница 1864: ...Connector Net Visual Studio Integration 1844 Figure 20 24 Debug Stepping Figure 20 25 Function Stepping 1 of 2 ...
Страница 2850: ...2830 ...
Страница 2854: ...2834 ...
Страница 2928: ...2908 ...
Страница 3000: ...2980 ...
Страница 3122: ...3102 ...
Страница 3126: ...3106 ...
Страница 3174: ...3154 ...
Страница 3232: ...3212 ...