Related Documentation Download this Manual
PDF (US Ltr)- 36.3 mb
PDF (A4)- 36.3 mb
Man Pages (TGZ)- 235.4Kb
Man Pages (Zip)- 347.1Kb
Info (Gzip)- 3.3Mb
Info (Zip)- 3.3Mb
Excerpts from this Manual

27.6.1 Compiling Programs with libmysqld

In precompiled binary MySQL distributions that includelibmysqld, the embedded server library, MySQL builds the library using the appropriate vendor compiler if there is one.

To get alibmysqldlibrary if you build MySQL from source yourself, you should configure MySQL with the-DWITH_EMBEDDED_SERVER=1option. See年代ection 2.9.7, “MySQL Source-Configuration Options”.

When you link your program withlibmysqld, you must also include the system-specificpthreadlibraries and some libraries that the MySQL server uses. You can get the full list of libraries by executingmysql_config --libmysqld-libs.

The correct flags for compiling and linking a threaded program must be used, even if you do not directly call any thread functions in your code.

To compile a C program to include the necessary files to embed the MySQL server library into an executable version of a program, the compiler needs to know where to find various files and needs instructions on how to compile the program. The following example shows how a program could be compiled from the command line, assuming that you are usinggcc, use the GNU C compiler:

gcc mysql_test.c -o mysql_test \ `/usr/local/mysql/bin/mysql_config --include --libmysqld-libs`

Immediately following thegcccommand is the name of the C program source file. After it, the-ooption is given to indicate that the file name that follows is the name that the compiler is to give to the output file, the compiled program. The next line of code tells the compiler to obtain the location of the include files and libraries and other settings for the system on which it is compiled. Themysql_configcommand is contained in backticks, not single quotation marks.

On some non-gccplatforms, the embedded library depends on C++ runtime libraries and linking against the embedded library might result in missing-symbol errors. To solve this, link using a C++ compiler or explicitly list the required libraries on the link command line.