Building MariaDB Connector/C++ from Source on Unix, Solaris and Mac OS X


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.

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

  1. CMake options: MariaDB 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 MariaDB Server installation path is not /usr/local/mysql and you want to build a debug version of the MariaDB 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 MariaDB 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 MariaDB 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. Make sure the dynamic library which is used in this case can be found at runtime:
    shell> export LD_LIBRARY_PATH=/usr/local/lib
    
  3. Now run the program to test your installation, substituting the appropriate host, user, password and database names for 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'
    ... MariaDB 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.

Retornar