0

I would like to use cURL with my project. I added this to my CMakelist :

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

This is the tree of my project :

CLion file tree

When I compile (with MinGW), I get this error :

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

I think curl is not properly linked, bt I don't know what I missed...

Pierre LAGOUTTE
  • 81
  • 1
  • 12
  • 1
    You have to tell CMake where cURL using "find" commands. How to use external libraries can be found at: https://stackoverflow.com/a/41909627/2799037 – usr1234567 Aug 16 '18 at 11:07
  • @usr1234567 Thank you, it was very helpful ! I wrote these lines to my CMakelist : `find_library(CURL_LIB curl)` ; `target_link_libraries(untitled "${CURL_LIB}")` and `target_include_directories(untitled PUBLIC include)`, but now I have a lot of "undefined reference". Is my CMakeList right ? – Pierre LAGOUTTE Aug 16 '18 at 16:42

1 Answers1

0

You need this three lines after installing libcurl on your computer and everything will be ok.

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

add_executable(exec_name tests-main.cpp)
target_link_libraries(exec_name curl)
Seek Addo
  • 1,871
  • 2
  • 18
  • 30