CMake:将 cURL 链接到我的项目:"cannot find -lcurl"

CMake : Linking cURL to my project : "cannot find -lcurl"

我想在我的项目中使用 cURL。我将其添加到我的 CMakelist 中:

include_directories(include)
link_directories(lib)
target_link_libraries(untitled curl)

这是我项目的树:

当我编译(使用 MinGW)时,我得到这个错误:

c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lcurl
collect2.exe: error: ld returned 1 exit status

我认为 curl 链接不正确,但我不知道我错过了什么...

在你的电脑上安装libcurl后需要这三行就可以了。

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lcurl")

add_executable(exec_name tests-main.cpp)
target_link_libraries(exec_name curl)