Pietro
Pietro

Reputation: 13150

Error building program with MySQL Connector C++

I have the following compile time error I cannot find the reason of:

fatal error: mysql_connection.h: No such file or directory

I am using cmake, and these are the CMakeLists.txt files:

# Top level CMakeLists.txt - MyProg

cmake_minimum_required (VERSION 2.6)
set (PROJECT_NAME "MyProg")

### Out-of-tree directories
set (UTILITIES_DIR "~/utilities")

### Configure header file to pass CMake's settings to the source code
configure_file (
    "Config.h.in"
    "${PROJECT_SOURCE_DIR}/Config.h"
    )

add_subdirectory (src "${CMAKE_CURRENT_BINARY_DIR}/obj")
add_subdirectory (${UTILITIES_DIR} "${CMAKE_CURRENT_BINARY_DIR}/obj/external/utilities")

and

# Source level CMakeLists.txt - MyProg/src

### MySQL Connector/C++ ###

set (MYSQLCONNECTORCPP_ROOT_DIR "~/3rdParty/mysql-connector-c++-1.1.0")

### Include paths ###

include_directories (${CMAKE_CURRENT_SOURCE_DIR})
include_directories (${UTILITIES_DIR})
include_directories (${MYSQLCONNECTORCPP_ROOT_DIR})
include_directories (/usr/local/include)

link_directories (/usr/local/lib)
link_directories (${MYSQLCONNECTORCPP_ROOT_DIR}/driver)
link_directories (/usr/lib64/mysql/)
link_directories (/usr/lib64/)
link_directories (/usr/local/mysql/lib/)

add_executable (myprog
    entrypoint.cpp
    MyProg.cpp
    MyProg_test.cpp
    ${UTILITIES_DIR}/DBInterface.cpp
    )

target_link_libraries (myprog mysqlcppconn-static mysqlclient)

This is the output from cmake (out of source build):

> cmake ../MyProg/
-- The C compiler identification is GNU 4.7.1
-- The CXX compiler identification is GNU 4.7.1
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- 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
-- Configuring done
-- Generating done
-- Build files have been written to: ~/MyProg_prj/Debug

And this is the fatal error I get from make:

> make
Scanning dependencies of target myprog
[  8%] Building CXX object obj/CMakeFiles/myprog.dir/entrypoint.cpp.o
In file included from ~/MyProg_prj/MyProg/src/entrypoint.cpp:18:0:
~/utilities/DBInterface.hpp:18:30: fatal error: mysql_connection.h: No such file or directory
compilation terminated.
make[2]: *** [obj/CMakeFiles/myprog.dir/entrypoint.cpp.o] Error 1
make[1]: *** [obj/CMakeFiles/myprog.dir/all] Error 2
make: *** [all] Error 2

The mysql_connection.h file is in the directory specified in the CMakeLists.txt file.

This problem happened after I upgraded Linux (before it worked correctly), but this should not be the reason. The PATH should contain everything needed.

Thank you.

Platform: Linux (OpenSuse), GCC 4.7.1, cmake, MySQL Connector C++ 1.1.0

Upvotes: 4

Views: 9407

Answers (2)

rsy
rsy

Reputation: 192

You are most likely missing the 'libmysqlcppconn-dev' library. Once installed, you shouldn't be seeing this error.

Upvotes: 4

Pietro
Pietro

Reputation: 13150

Before updating the system, in the source code I included the MySQL header like this:

#include <mysql_connection.h>

Now I have to specify the subdirectory:

#include <driver/mysql_connection.h>

Something must have changed in how the paths are set...

Upvotes: 0

Related Questions