c++ - 在 CLion/Mingw 上未定义对“curl_easy_init”的引用
问题描述
我正在尝试在 C++ 代码中使用 curl。我应该怎么做?
我已将 libcurl.a 和 libcurl.dll.a 粘贴到此目录中:C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\lib
这是我来自 CLion/Mingw 的 CMakeLists.txt
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:
CMakeFiles\tan.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
. 最后一行解决了这个问题。
步骤1:
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 运行程序(在我的情况下为 tan.exe)。从 curl 包中获取该 dll(在我的情况下为 curl-7.65.0-win64-mingw)并将其放在可执行文件的一侧。确保 curl 和您的可执行文件是使用相同的编译器编译的。在我的情况下,它是Mingw。
推荐阅读
- visual-studio - UDMF 驱动程序:visual studio 2019:项目属性中没有“部署”选项
- sql - 需要根据原始购买渠道来隔离全渠道客户 - SQL
- python - 如何将具有不同日期格式的 Pandas 列从对象转换为 Datetime 类型?
- apache-spark - 当 --deploy-mode 为集群时,“ImportError: No module named sklearn”
- c++ - 'Car' 的复制构造函数被隐式删除,因为变量字段 'fuelType' 具有非平凡的复制构造函数
- r - 如何在图形边框的最边缘放置刻度线?(ggplot)
- airflow - Airflow 2.0.2 - 尚未创建用户
- elasticsearch - 添加 Elasticsearch 节点,是否需要复制 internal_users.yml 文件和其他配置?
- jupyter-notebook - google-dataproc 不断崩溃并出现错误 504
- seq-logging - 从满足某些条件的请求中获取所有 Seq 日志