CURL

Answered

Hi all,

I been stuck on a issue with clion for the past week and can not get it to work. I downloaded CLION on windows 10 and I am using MinGW as my compiler. I download CURL from the curl website but now I'm not sure what to put on cmake in order for my project to be able to use the curl lib. I have a simple hello world project with the #include <curl/curl.h> header and I get this error: fatal error: "curl/curl.h: No such file or directory compilation terminated." What do I put my in my cmake file in order for this to compile? My curl download is in c:/curl-7.54.0-win32-mingw. I'm even which file I should point it to within the curl folder? The lib or include? Any help would much be appreciated.

Thanks,

Alex

0
4 comments

Hi.

You need to set the following commands in your CMakeLists:

find_package(CURL)
IF (CURL_FOUND)
include_directories(${CURL_INCLUDE_DIRS})
target_link_libraries(target ${CURL_LIBRARIES})
endif()

Also please take a look at our quick CMake tutorial or CMake documentation.

0
Avatar
Permanently deleted user

I have tried that, the error I get now is "Cannot specify link libraries for target "curl_test" which is not built by
this project." Do you have any ideas what I am doing wrong?

Thanks

0

The solution is explained in this Stack overflow answer: https://stackoverflow.com/a/41262868
Basically that you need is find first the Package then add the executable and finally link the libraries to your executable.

project(test_comparator)

It works for me:

find_package(CURL REQUIRED)

add_executable(test_comparator main.cpp)

if(CURL_FOUND)
include_directories(${CURL_INCLUDE_DIR})
target_link_libraries(test_comparator ${CURL_LIBRARIES})
else(CURL_FOUND)
message(FATAL_ERROR "Could not find the CURL library and development files.")
endif(CURL_FOUND)

 

It don't works for me:

find_package(CURL REQUIRED)

if(CURL_FOUND)
include_directories(${CURL_INCLUDE_DIR})
target_link_libraries(test_comparator ${CURL_LIBRARIES})
else(CURL_FOUND)
message(FATAL_ERROR "Could not find the CURL library and development files.")
endif(CURL_FOUND)

add_executable(test_comparator main.cpp)

Console error:

CMake Error at CMakeLists.txt:10 (target_link_libraries):
Cannot specify link libraries for target "test_comparator" which is not
built by this project.

0

Error

====================[ Build | ProgLab_Project1 | Debug ]========================
"C:\Program Files\JetBrains\CLion 2023.1.5\bin\cmake\win\x64\bin\cmake.exe" --build C:\Users\ozgur\GitHub\ProgLab_Project1\cmake-build-debug --target ProgLab_Project1 -- -j 10
C:/Users/ozgur/SDL2-2.28.1/x86_64-w64-mingw32/include/SDL2
mingw32;-mwindows;C:/Users/ozgur/SDL2-2.28.1/x86_64-w64-mingw32/lib/libSDL2main.a;C:/Users/ozgur/SDL2-2.28.1/x86_64-w64-mingw32/lib/libSDL2.dll.a
mingw32;-mwindows;C:/Users/ozgur/SDL2-2.28.1/x86_64-w64-mingw32/lib/libSDL2main.a;C:/Users/ozgur/SDL2-2.28.1/x86_64-w64-mingw32/lib/libSDL2.dll.a
-- Configuring incomplete, errors occurred!
CMake Error at C:/Program Files/JetBrains/CLion 2023.1.5/bin/cmake/win/x64/share/cmake-3.26/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
 Could NOT find CURL (missing: CURL_INCLUDE_DIR)
Call Stack (most recent call first):
 C:/Program Files/JetBrains/CLion 2023.1.5/bin/cmake/win/x64/share/cmake-3.26/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
 C:/Program Files/JetBrains/CLion 2023.1.5/bin/cmake/win/x64/share/cmake-3.26/Modules/FindCURL.cmake:182 (find_package_handle_standard_args)
 CMakeLists.txt:17 (find_package)


mingw32-make: *** [Makefile:178: cmake_check_build_system] Error 1



CMake

cmake_minimum_required(VERSION 3.26)
project(ProgLab_Project1 C)
set(CMAKE_C_STANDARD 11)

set(SDL2_PATH "C:\\Users\\ozgur\\SDL2-2.28.1\\x86_64-w64-mingw32")
find_package(SDL2 REQUIRED)
include_directories( ${SDL2_INCLUDE_DIR} )

message("${SDL2_INCLUDE_DIR}")
message("${SDL2_LIBRARY}")
add_executable(ProgLab_Project1 main.c)

target_link_libraries(ProgLab_Project1 ${SDL2_LIBRARY} )
message("${SDL2_LIBRARY}")

set(CURL_LIBRARY "-lcurl")  # This sets the library name to link
find_package(CURL REQUIRED)

add_executable(ProgLab_Project1 main.c)

target_link_libraries(ProgLab_Project1 ${CURL_LIBRARIES})
target_link_libraries(eCAD Qt5::Widgets Qt5::Core)

How I can solve this problem ? 

0

Please sign in to leave a comment.