1

Maybe its a stupid question but I have an program that I need -lmysqlcppconn -lreadline and -lpthread.

I'm using the cmake to generate the makefile for that I resolve use :

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -lmysqlcppconn -lreadline -lpthread")
...(other command most likely irrelevant)

add_executable(name ${SOURCES} ${CMAKE_CXX_FLAG})

but I received the follow warning when I execute the makefile :

clang: warning: -lmysqlcppconn: 'linker' input unused
clang: warning: -lreadline: 'linker' input unused
clang: warning: -lpthread: 'linker' input unused

Exists a better way to do it?

warwcat
  • 309
  • 3
  • 5
  • 13

1 Answers1

3

CMAKE_CXX_FLAGS is for compiler flags (with CMake-generated make files compilation and linking are separate steps). To link you need something like

target_link_libraries(name mysqlcppconn)
target_link_libraries(name readline)
target_link_libraries(name pthread)

For threading library a better way is to follow the process explained in this answer

Community
  • 1
  • 1
bobah
  • 18,364
  • 2
  • 37
  • 70
  • CMake Error at CMakeLists.txt:15 (target_link_libraries): Cannot specify link libraries for target "eyeTyou" which is not built by this project. I tryed that before but I don't know to link this libraries – warwcat Aug 09 '16 at 16:31
  • Sorry , my error I don't expected that I needed to cal target_link_libraries(...) after the add_executable(...) that works – warwcat Aug 09 '16 at 16:54
  • Doesn't work for me. Not even calling it after add_executable. –  Jun 08 '21 at 09:43
  • I had a problem with "undefined reference to `get_driver_instance'", adding the linker flags in other possible ways did not help, but finally adding it this way resolved the problem. – Jan Fiołka Jan 24 '23 at 22:38