22.5.2.1. Building source on Unix, Solaris and Mac OS X

  1. Run CMake to build a Makefile:

    shell> me@host:/path/to/mysql-connector-cpp> 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/

    On non-Windows systems, CMake first checks to see if the CMake variable MYSQL_CONFIG_EXECUTABLE is set. If it is not found CMake tries to locate mysql_config in the default locations.

    If you have any problems with the configure process please check the troubleshooting instructions below.

  2. Use make to build the libraries. First make sure you have a clean build:

    shell> me@host:/path/to/mysql-connector-cpp> make clean

    Then build the connector:

    me@host:/path/to/mysql-connector-cpp> make
    [  1%] Building CXX object »
    driver/CMakeFiles/mysqlcppconn.dir/mysql_connection.o
    [  3%] Building CXX object »
    driver/CMakeFiles/mysqlcppconn.dir/mysql_constructed_resultset.o
    [...]
    [100%] Building CXX object examples/CMakeFiles/statement.dir/statement.o
    Linking CXX executable statement

    If all goes well, you will find the MySQL Connector/C++ library in /path/to/cppconn/libmysqlcppconn.so.

  3. Finally make sure the header and library files are installed to their correct locations:

    make install

    Unless you have changed this in the configuration step, the header files will be copied to the directory /usr/local/include. The header files copied are mysql_connection.h and mysql_driver.h.

    Again, unless you have specified otherwise, the library files will be copied to /usr/local/lib. The files copied are libmysqlcppcon.so, the dynamic library, and libmysqlcppconn-static.a, the static library.

If you encounter any errors, please first carry out the checks shown below:

  1. CMake options: MySQL installation path, debug version and more

    In case of configuration or compilation problems, check the list of CMake options:

    shell> me@host:/path/to/mysql-connector-cpp> cmake -L
    [...]
    CMAKE_BACKWARDS_COMPATIBILITY:STRING=2.4
    CMAKE_BUILD_TYPE:STRING=
    CMAKE_INSTALL_PREFIX:PATH=/usr/local
    EXECUTABLE_OUTPUT_PATH:PATH=
    LIBRARY_OUTPUT_PATH:PATH=
    MYSQLCPPCONN_GCOV_ENABLE:BOOL=0
    MYSQLCPPCONN_TRACE_ENABLE:BOOL=0
    MYSQL_CONFIG_EXECUTABLE:FILEPATH=/usr/bin/mysql_config

    For example, if your MySQL Server installation path is not /usr/local/mysql and you want to build a debug version of the MySQL Connector/C++ use:

    shell> me@host:/path/to/mysql-connector-cpp> cmake »
    -D CMAKE_BUILD_TYPE:STRING=Debug »
    -D MYSQL_CONFIG_EXECUTABLE=/path/to/my/mysql/server/bin/mysql_config .
  2. Verify your settings with cmake -L:

    shell> me@host:/path/to/mysql-connector-cpp> cmake -L
    [...]
    CMAKE_BACKWARDS_COMPATIBILITY:STRING=2.4
    CMAKE_BUILD_TYPE:STRING=
    CMAKE_INSTALL_PREFIX:PATH=/usr/local
    EXECUTABLE_OUTPUT_PATH:PATH=
    LIBRARY_OUTPUT_PATH:PATH=
    MYSQLCPPCONN_GCOV_ENABLE:BOOL=0
    MYSQLCPPCONN_TRACE_ENABLE:BOOL=0
    MYSQL_CONFIG_EXECUTABLE=/path/to/my/mysql/server/bin/mysql_config

    Proceed by carrying out a make clean command followed by a make command, as described above.

Once you have installed MySQL Connector/C++ you can carry out a quick test to check the installation. To do this you can 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 the connector has been correctly installed. This procedure assumes you have a working MySQL Server that you can connect to.

  1. First compile the example. To do this change to the examples directory and type:

    shell> g++ -o test_install -I/usr/local/include -I/usr/local/include/cppconn -Wl,-Bdynamic -lmysqlcppconn standalone_example.cpp
  2. You need to make sure the dynamic library which is used in this case can be found at run time. To do this enter:

    shell> export LD_LIBRARY_PATH=/usr/local/lib
    
  3. Now run the program to test your installation, exchanging the host, user, password and database to be accessed given below to match your system:

    ./test_install localhost root password database

    You will see something 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 http://www.mysql.com
    

    If you see any errors take note of them and go through the troubleshooting procedures discussed earlier.

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