cmake issue: undefined reference to a MySQL library-Collection of common programming errors
With the following CMakeFiles.txt files for cmake, I get the linker error:
CMakeFiles/MyPrj.dir/src1.cpp.o: In function ...:
src1.cpp: undefined reference to 'sql::mysql::get_driver_instance()'
collect2: ld returned 1 exit status
The same program compiles correctly in the NetBeans environment (without using cmake).
Top level CMakeFiles.txt:
cmake_minimum_required(VERSION 2.8.0)
project(MyPrj)
# --- MySQL Connector path
set(MYSQL_CONNECTOR_PATH "/path/to/mysql-connector-c++-1.1.0")
# --- Automatically built configuration header file
configure_file(
"MyPrjConfig.h.in"
"${MyPrj_BINARY_DIR}/MyPrjConfig.h"
)
# --- Add the binary tree to the search path for include files
include_directories(
"${MyPrj_BINARY_DIR}"
)
add_subdirectory(src)
Lower level CMakeFiles.txt:
include_directories(${MYSQL_CONNECTOR_PATH})
link_directories (
/lib64
/lib
${MYSQL_CONNECTOR_PATH}/driver
)
add_executable ( myProg
src1.cpp
src2.cpp
src3.cpp
)
target_link_libraries ( myProg
mysqlcppconn-static
mysqlclient
)
Thank you!
Originally posted 2013-11-09 23:28:40.