Documentation Home
MySQL Connector/C++ Developer Guide
Related Documentation Download this Manual
PDF (US Ltr) - 0.6Mb
PDF (A4) - 0.6Mb
HTML Download (TGZ) - 431.1Kb
HTML Download (Zip) - 450.0Kb

MySQL Connector/C++ Developer Guide  /  Installing Connector/C++ from Source  /  Installing Connector/C++ from Source on Unix and Unix-Like Systems

4.3 Installing Connector/C++ from Source on Unix and Unix-Like Systems

To install Connector/C++ from source, your system must satisfy the requirements outlined in Section 4.1, “Source Installation System Prerequisites”.

  1. Change location to the top-level directory of the source distribution:

    shell> cd /path/to/mysql-connector-cpp
  2. Run CMake to build a Makefile:

    shell> cmake .
    -- Check for working C compiler: /usr/local/bin/gcc
    -- Check for working C compiler: /usr/local/bin/gcc -- works
    -- Generating done
    -- Build files have been written to: /path/to/mysql-connector-cpp/

    To use configuration values different from the defaults, use the options described at Section 4.6, “Connector/C++ Source-Configuration Options”.

    On non-Windows systems, CMake checks to see whether the MYSQL_CONFIG_EXECUTABLE CMake option is set. If not, CMake tries to locate mysql_config in the default locations.

  3. Use make to build Connector/C++. First make sure you have a clean build, then build the connector:

    shell> make clean
    shell> make
    [  1%] Building CXX object »
    [  3%] Building CXX object »
    [100%] Building CXX object examples/CMakeFiles/statement.dir/statement.o
    Linking CXX executable statement

    If all goes well, you will find the Connector/C++ library in the driver directory.

  4. Install the header and library files:

    shell> make install

    Unless you have changed the location in the configuration step, make install copies the header files to the directory /usr/local/include. The header files copied are mysql_connection.h and mysql_driver.h.

    Again, unless you have specified otherwise, make install copies the library files to /usr/local/lib. The files copied are the dynamic library, and the static library libmysqlcppconn-static.a. The dynamic library file name extension might differ on your system (for example, .dylib on OS X).

After installing Connector/C++, you can carry out a quick test to check the installation. To do this, compile and run one of the example programs, such as examples/standalone_example.cpp. This example is discussed in more detail later, but for now, you can use it to test whether the connector has been correctly installed. This procedure assumes that you have a working MySQL Server to which you can connect. It also assumes header and library locations of /usr/local/include and /usr/local/lib, respectively; adjust these as necessary for your system.

  1. Compile the example program. To do this, change location to the examples directory and enter this command:

    shell> g++ -o test_install \
      -I/usr/local/include -I/usr/local/include/cppconn \
      -Wl,-Bdynamic standalone_example.cpp -lmysqlcppconn
  2. Make sure the dynamic library which is used in this case can be found at runtime:

    shell> export LD_LIBRARY_PATH=/usr/local/lib

    On OS X, try this:

    shell> export DYLD_LIBRARY_PATH=/usr/local/lib
  3. Now run the program to test your installation, substituting the appropriate host, user, password, and database arguments for your system:

    shell> ./test_install localhost root password database

    You should see output similar to the following:

    Connector/C++ standalone program example...
    ... running 'SELECT 'Welcome to Connector/C++' AS _message'
    ... MySQL replies: Welcome to Connector/C++
    ... say it again, MySQL
    ....MySQL replies: Welcome to Connector/C++
    ... find more at

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