I have some code I wrote on my mac machine and it has been working perfectly but when I port it over to a Linux machine I get an undefined reference to curl_easy_init<
Never add -l
flags to CMAKE_EXE_LINKER_FLAGS and moreover to CMAKE_CXX_FLAGS (the flag -l
is for the linker, not for a compiler).
For link with libraries use target_link_libraries: it is specifically intended for that purpose:
target_link_libraries(<your-executable> curl)
When you add a flag to *_FLAGS
variable, the flag is added before the source file (object file actually) in the linker's command-line. If the source file uses some function from the library, then the linker cannot find it.
As opposite, a flag produced by command target_link_libraries
is added after the source file in the linker's command line.