Search code examples
c++mysql-connectorbuild-error

Using MySQL Connector/C++ v2.0 with CMake?


I'm trying to use MySQL Connector/C++ v2 in my application, I'm using CLion as IDE, so I build using CMake, but I can't manage to make CMake understand that I need it.

I included MySQL Connector/C++ like this:

# Build external libs
add_subdirectory(external/mysql-connector-cpp)

and I simply added:

# Add libs
target_link_libraries(libconcpp)

My CMake environnement is reloading greatly, but I get a linking error as the lib was not included.. I also add includes with the correct directive in CMakeLists.txt.

Thanks !


Solution

  • The problem is that in your target_link_libraries() you missed specifying the target:

    target_link_libraries(libconcpp)
    

    It should be:

    target_link_libraries(myTargetName libconcpp) 
    

    where myTargetName is the name of your target you specified in add_excecutable() or add_library().