CURL
已回答
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
请先登录再写评论。
Hi.
You need to set the following commands in your CMakeLists:
Also please take a look at our quick CMake tutorial or CMake documentation.
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
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.
It works for me:
It don't works for me:
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.
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 ?