我正在尝试将libcurl链接到简单项目。
这是完整的源代码(main.cpp
):
#include <bits/stdc++.h>
#include <curl/curl.h>
int main() {
CURL *curl = curl_easy_init();
if(curl) {
std::cout << "Hello, CURL\n";
curl_easy_cleanup(curl);
}
return 0;
}
所有标题都位于C:\Libs\libcurl\include\curl
中,并且
libcurl.a
位于C:\Libs\libcurl\lib
。
我的CMakeLists.txt
:
cmake_minimum_required(VERSION 3.9)
project(Playground)
set(CMAKE_CXX_STANDARD 17)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
set(SOURCE_FILES main.cpp)
add_executable(Playground ${SOURCE_FILES})
find_package(Libcurl REQUIRED)
include_directories(${LIBCURL_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} ${LIBCURL_LIBRARY})
和FindLibCurl.cmake
(位于/ cmake目录中):
set(FIND_LIBCURL_PATHS
C:/Libs/libcurl)
find_path(LIBCURL_INCLUDE_DIR curl/*
PATH_SUFFIXES include
PATHS ${FIND_LIBCURL_PATHS})
find_library(LIBCURL_LIBRARY
NAMES libcurl
PATH_SUFFIXES lib
PATHS ${FIND_LIBCURL_PATHS})
当我尝试构建项目时,出现以下错误:
[ 50%] Linking CXX executable Playground.exe
CMakeFiles\Playground.dir\build.make:86: recipe for target 'Playground.exe' failed
CMakeFiles\Playground.dir/objects.a(main.cpp.obj): In function `main':
D:/Clion_projects/Playground/main.cpp:5: undefined reference to `_imp__curl_easy_init'
D:/Clion_projects/Playground/main.cpp:8: undefined reference to `_imp__curl_easy_cleanup'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [Playground.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/Playground.dir/all] Error 2
CMakeFiles\Makefile2:71: recipe for target 'CMakeFiles/Playground.dir/all' failed
mingw32-make.exe[1]: *** [CMakeFiles/Playground.dir/rule] Error 2
CMakeFiles\Makefile2:83: recipe for target 'CMakeFiles/Playground.dir/rule' failed
mingw32-make.exe: *** [Playground] Error 2
Makefile:117: recipe for target 'Playground' failed
那我想念什么?