Flag '-l' in CMAKE_CXX_FLAGS doesn't work

前端 未结 1 837
无人共我
无人共我 2020-12-21 11:10

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<

1条回答
  •  攒了一身酷
    2020-12-21 11:18

    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( 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.

    0 讨论(0)
提交回复
热议问题