MySQL Router 2.1  /  ...  /  Compiling the Source Code

2.4.2 Compiling the Source Code

To compile the source code, you should create a folder to contain the compiled binaries and executables, run cmake to create the make file, then compile the code. The following demonstrates the steps needed on a Ubuntu machine. Other platforms are similar.


For some platforms, such as Oracle Enterprise Linux 6, you may also need to install the devtoolset software collection.

If you get an error stating that the MySQL libraries cannot be found, then check the listed paths. If the client libraries or the include folder does not exist, you may need to reference a compiled copy of the MySQL Server source code by using the -DWITH_MYSQL=<path to server code> option. More specifically, the compiler needs to be able to find the MySQL client libraries and include files. If libmysqlclient is stored elsewhere, then -DMySQL_CLIENT_LIB=/path/to/ can also be used. A compiled server source code tree will have these files. So too will most installations of the MySQL server.

For example, on Debian and RPM-based platforms, you would need the packages which contain the libraries and the development (include) files. If you installed MySQL from a platform-specific repository, you would need to install the mysql-community-libs and mysql-community-devel packages.


If you change anything and need to recompile from scratch, be sure to delete the CMakeCache.txt file before running the cmake command.

Begin by running the cmake command to create the makefile. The following commands are run from the root of the MySQL Router source code tree. You should see similar results with the appropriate paths for your system.

shell>  mkdir build
shell>  cd build
shell>  cmake ..  -DWITH_MYSQL=<path to binaries and libraries>
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Loading internal repository
-- Installation layout set to DEFAULT
-- Adding MySQL Harness from /home/cbell/source/git/mysql-router-2.0.2/mysql_harness
-- Harness will install plugins in lib/mysqlrouter
-- MySQL Harness CPU Descriptor is x86_64
-- MySQL Harness OS Descriptor is linux
-- MySQL Harness Compiler Descriptor is gnu-3
-- MySQL Harness Runtime Descriptor is *
-- Found Doxygen: /usr/bin/doxygen (found version "")
-- Performing Test COMPILER_SUPPORTS_CXX11
-- Performing Test COMPILER_SUPPORTS_CXX11 - Success
-- Performing Test COMPILER_SUPPORTS_CXX0X - Success
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Performing Test support_11
-- Performing Test support_11 - Success
-- Performing Test support_0x
-- Performing Test support_0x - Success
-- Found MySQL Libraries 5.6.27; using <path to server code>/lib/
-- Loading module 'router'
-- Loading module 'routing'
-- Configuring done
-- Generating done
-- Build files have been written to: <path to router code>/build

Next, compile the code. For this we only need the make command as shown. Again, you should see similar results on your system.

shell>  make
Scanning dependencies of target harness-archive
[  2%] Building CXX object harness/harness/CMakeFiles/harness-archive.dir/src/
[  5%] Building CXX object harness/harness/CMakeFiles/harness-archive.dir/src/
[  8%] Building CXX object harness/harness/CMakeFiles/harness-archive.dir/src/
[ 11%] Building CXX object harness/harness/CMakeFiles/harness-archive.dir/src/
[ 14%] Building CXX object harness/harness/CMakeFiles/harness-archive.dir/src/
Linking CXX static library libmysqlharness.a
[ 14%] Built target harness-archive
Scanning dependencies of target harness-library
[ 17%] Building CXX object harness/harness/CMakeFiles/harness-library.dir/src/
[ 20%] Building CXX object harness/harness/CMakeFiles/harness-library.dir/src/
[ 22%] Building CXX object harness/harness/CMakeFiles/harness-library.dir/src/
[ 25%] Building CXX object harness/harness/CMakeFiles/harness-library.dir/src/
[ 28%] Building CXX object harness/harness/CMakeFiles/harness-library.dir/src/
Linking CXX shared library
[ 28%] Built target harness-library
Scanning dependencies of target logger
[ 31%] Building CXX object harness/plugins/logger/CMakeFiles/logger.dir/
Linking CXX shared library ../../../stage/lib/mysqlrouter/
[ 31%] Built target logger
Scanning dependencies of target keepalive
[ 34%] Building CXX object harness/plugins/keepalive/CMakeFiles/keepalive.dir/src/
Linking CXX shared library ../../../stage/lib/mysqlrouter/
[ 34%] Built target keepalive
Scanning dependencies of target router_lib
[ 37%] Building CXX object src/router/src/CMakeFiles/router_lib.dir/
[ 40%] Building CXX object src/router/src/CMakeFiles/router_lib.dir/
[ 42%] Building CXX object src/router/src/CMakeFiles/router_lib.dir/
[ 45%] Building CXX object src/router/src/CMakeFiles/router_lib.dir/
[ 48%] Building CXX object src/router/src/CMakeFiles/router_lib.dir/
Linking CXX shared library ../../../stage/lib/
[ 48%] Built target router_lib
Scanning dependencies of target mysqlrouter
[ 51%] Building CXX object src/router/src/CMakeFiles/mysqlrouter.dir/
Linking CXX executable ../../../stage/bin/mysqlrouter
[ 51%] Built target mysqlrouter
Scanning dependencies of target routing
[ 77%] Building CXX object src/routing/CMakeFiles/routing.dir/src/
[ 80%] Building CXX object src/routing/CMakeFiles/routing.dir/src/
[ 82%] Building CXX object src/routing/CMakeFiles/routing.dir/src/
[ 85%] Building CXX object src/routing/CMakeFiles/routing.dir/src/
[ 88%] Building CXX object src/routing/CMakeFiles/routing.dir/src/
[ 94%] Building CXX object src/routing/CMakeFiles/routing.dir/src/
[ 97%] Building CXX object src/routing/CMakeFiles/routing.dir/src/
[100%] Building CXX object src/routing/CMakeFiles/routing.dir/src/
Linking CXX shared library ../../stage/lib/mysqlrouter/
[100%] Built target routing

User Comments
Sign Up Login You must be logged in to post a comment.