在CLion/Mingw上对"curl_easy_init"的未定义引用

undefined reference to `curl_easy_init' on CLion/Mingw

本文关键字:easy init 引用 未定义 curl CLion Mingw 上对      更新时间:2023-10-16

我正在尝试在C 代码中使用卷曲。我应该如何正确地做?

我粘贴了libcurl.a&libcurl.dll.a在此目录中:C: Program Files Mingw-W64 x86_64-8.1.0-posix-seh-seh-rt_v6-rev0 mingw64 lib

这是我的cmakelists.txt,来自clion/mingw

cmake_minimum_required(VERSION 3.3) 
project(tan)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -lcurl.dll")
add_executable(tan Tan/mail.cpp)
project(untitled6)

当我添加" #define curl_staticlib"时,我会得到以下错误:

reference to `curl_easy_init'
C:/Users/John/CLionProjects/tan/Tan/mail.cpp:84: undefined  
reference to `curl_easy_setopt'
C:/Users/John/CLionProjects/tan/Tan/mail.cpp:86: undefined reference to `curl_easy_setopt'
C:/Users/John/CLionProjects/tan/Tan/mail.cpp:91: undefined reference to `curl_slist_append'
C:/Users/John/CLionProjects/tan/Tan/mail.cpp:92: undefined reference to `curl_slist_append'
C:/Users/John/CLionProjects/tan/Tan/mail.cpp:93: undefined reference to `curl_easy_setopt'
C:/Users/John/CLionProjects/tan/Tan/mail.cpp:98: undefined reference to `curl_easy_setopt'
C:/Users/John/CLionProjects/tan/Tan/mail.cpp:99: undefined reference to `curl_easy_setopt'
C:/Users/John/CLionProjects/tan/Tan/mail.cpp:100: undefined reference to `curl_easy_setopt'
C:/Users/John/CLionProjects/tan/Tan/mail.cpp:103: undefined reference to `curl_easy_perform'
C:/Users/John/CLionProjects/tan/Tan/mail.cpp:107: undefined reference to `curl_easy_strerror'
C:/Users/John/CLionProjects/tan/Tan/mail.cpp:111: undefined reference to `curl_slist_free_all'
C:/Users/John/CLionProjects/tan/Tam/mail.cpp:121: undefined reference to ````curl_easy_cleanup
Without "#define CURL_STATICLIB" i get these errors:
CMakeFilestan.dir/objects.a(mail.cpp.obj): In function `main':
C:/Users/John/CLionProjects/tan/Tan/mail.cpp:81: undefined reference to `__imp_curl_easy_init'
C:/Users/John/CLionProjects/tan/Tan/mail.cpp:84: undefined reference to `__imp_curl_easy_setopt'
C:/Users/John/CLionProjects/tan/Tan/mail.cpp:86: undefined reference to `__imp_curl_easy_setopt'
C:/Users/John/CLionProjects/tan/Tan/mail.cpp:91: undefined reference to `__imp_curl_slist_append'
C:/Users/John/CLionProjects/tan/Tan/mail.cpp:92: undefined reference to `__imp_curl_slist_append'
C:/Users/John/CLionProjects/tan/Tan/mail.cpp:93: undefined reference to `__imp_curl_easy_setopt'
C:/Users/John/CLionProjects/tan/Tan/mail.cpp:98: undefined reference to `__imp_curl_easy_setopt'
C:/Users/John/CLionProjects/tan/Tan/mail.cpp:99: undefined reference to `__imp_curl_easy_setopt'
C:/Users/John/CLionProjects/tan/Tan/mail.cpp:100: undefined reference to `__imp_curl_easy_setopt'
C:/Users/John/CLionProjects/tan/Tan/mail.cpp:103: undefined reference to `__imp_curl_easy_perform'
C:/Users/John/CLionProjects/tan/Tan/mail.cpp:107: undefined reference to `__imp_curl_easy_strerror'
C:/Users/John/CLionProjects/tan/Tan/mail.cpp:111: undefined reference to `__imp_curl_slist_free_all'
C:/Users/John/CLionProjects/tan/Tan/mail.cpp:121: undefined reference to `__imp_curl_easy_cleanup'

如果有人来看,请在CMakeLists.txt中使用此。最后一行解决了问题。

step1: Copy libcurl.dll.a in C:/curl. No need to copy "libcurl.a" OR "libcurl.dll.a" at any other place. No need for #define CURL_STATICLIB in main.cpp file

step2:Edit the CMakeLists.txt如下。

set(CMAKE_CXX_STANDARD 14)                                     
add_executable(tan Tan/mail.cpp)
project(untitled6)
target_link_libraries(tan "C:/curl/libcurl.dll.a")

step3:如果您的程序快速闪烁并关闭。您可能会缺少一些DLL文件。要检查您缺少哪些内容,请使用CMD运行程序(在我的情况下(。从curl软件包(在我的情况下,curl-7.65.0-win64-mingw(取DLL,然后将其放在可执行文件的侧面。确保用同一编译器对卷发和可执行文件进行编译。就我而言,它是mingw。