To install Connector/C++ from source, verify that your system satisfies the requirements outlined in Section 4.1, “Source Installation System Prerequisites”.
Change location to the top-level directory of your Connector/C++ source distribution, then run CMake to build a
To use configuration values different from the defaults, use the options described at Section 4.6, “Connector/C++ Source-Configuration Options”. For example, to specify the installation location explicitly, use the
CMake checks to see whether the
MYSQL_CONFIG_EXECUTABLECMake option is set. If not, CMake tries to locate
mysql_configin the default locations.
Use make to build Connector/C++. First make sure you have a clean build, then build the connector:
make clean make
If all goes well, you will find the Connector/C++ library in the
Install the header and library files:
Unless you have changed the installation location in the configuration step by specifying the
CMAKE_INSTALL_PREFIXCMake option, make install copies the header files to the directory
mysql_driver.hheader files are copied.
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,
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 availability of 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 macOS, try this:
It may also be necessary to run ldconfig or equivalent utility.
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