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.
- 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 MariaDB Connector/C++ library in
/path/to/cppconn/libmysqlcppconn.so
. - 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 are copied to the directory
/usr/local/include
. The header files copied aremysql_connection.h
andmysql_driver.h
.Again, unless you have specified otherwise, the library files are copied to
/usr/local/lib
. The files copied arelibmysqlcppconn.so
, the dynamic library, andlibmysqlcppconn-static.a
, the static library.
If you encounter any errors, please first carry out the checks shown below:
- 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 .
- 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.
- 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
- Make sure the dynamic library which is used in this case can be found at runtime:
shell> export LD_LIBRARY_PATH=/usr/local/lib
- 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.