To install Connector/C++ from source, your system must satisfy the requirements outlined in Section 4.1, “Source Installation System Prerequisites”.
Change location to the top-level directory of the source distribution:
Run CMake to build a
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:
To use configuration values different from the defaults, use the options described at Section 4.7, “Connector/C++ Source-Configuration Options”.
On non-Windows systems, CMake checks to see whether the
MYSQL_CONFIG_EXECUTABLECMake option is set. If not, CMake tries to locate
mysql_configin the default locations.
If you have any problems with the configuration process, check the troubleshooting instructions given in Section 4.5, “Troubleshooting Connector/C++ Source Installation Problems”.
Use make to build Connector/C++. First make sure you have a clean build, then build the connector:
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 Connector/C++ library in the
Install the header and library files:
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
Again, unless you have specified otherwise, make install copies the library files to
/usr/local/lib. The files copied are the dynamic library
libmysqlcppconn.so, and the static library
libmysqlcppconn-static.a. The dynamic library file name extension might differ on your system (for example,
.dylibon 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/lib, respectively; adjust these as
necessary for your system.
Compile the example program. To do this, change location to the
examplesdirectory and enter this command:
g++ -o test_install \
-I/usr/local/include -I/usr/local/include/cppconn \
-Wl,-Bdynamic standalone_example.cpp -lmysqlcppconn
Make sure the dynamic library which is used in this case can be found at runtime:
On OS X, try this:
Now run the program to test your installation, substituting the appropriate host, user, password, and database arguments for your system:
./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 http://www.mysql.com
If you see any errors, take note of them and go through the troubleshooting procedures in Section 4.5, “Troubleshooting Connector/C++ Source Installation Problems”.