cmake_minimum_required(VERSION 3.15)
project(linkCurl VERSION 1.0 LANGUAGES CXX)
find_package(CURL REQUIRED)
include_directories(${libcurl_CURL_libcurl_INCLUDE_DIRS_RELEASE})
add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} ${CURL_LIBRARIES})
Build commands:
C:\Users\torsiver\Projects\link_curl>conan install . --output-folder=build --build=missing [Seems to run OK - conan downloads the package]
cd build
C:\Users\torsiver\Projects\link_curl\build>cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release [seems to run OK]
C:\Users\torsiver\Projects\link_curl\build>cmake --build . [causes ERROR: error LNK2019: unresolved external symbol __imp_curl_easy_strerror]
I tried running with -v which shows this link command:
It seems CURL_LIBRARIES is not set. I tried to use CURL::libcurl as shown below (the variable libcurl_LIBRARIES_RELEASE has this value so maybe i should be using this to get windows and linux consistent):
This makes no difference (edited because my first conclusion was wrong, caused by an experiment).
It seems Conan has correctly downloaded the curl lib (this file exists after running Conan install: c:\Users\torsiver.conan2\p\libcu75d014a1ff3cb\p\lib\libcurl.lib), but somehow CMake is not picking it up correctly under windows.
CMake uses the correct include path during compile, so find_package must have found the correct curl from Conan
The reason i am not sure is that the find_package documentation says that HINTS accepts a directory name as argument, but CURL_USE_STATIC_LIBS does not look like a directory name.
Doing this made no difference. Do i need more changes (specify someting different than CURL::libcurl to target_link_libraries, maybe?)
I would copy the set_target_properties call(s) and change set_target_properties to message. It’ll drop spaces, but it should be good enough to see if things are at least sane.
This feels like something Conan is not setting up properly rather than CMake’s FindCURL. I’d ask the Conan folks about it, but if something is wrong on CMake’s side, feel free to report back here.