我终于能够正确地(我认为)将cURL链接到代码块(GNU编译器)并将所有dll问题排序。它能够正确编译和运行一次,然后停止处理与libcurl.a(url.o)相关的新错误。这两个错误是
undefined reference to 'idna_to_ascii_lz'
undefined reference to 'string_prep_locale_charset'.
之前成功的构建之后出现了错误,这对我来说没有意义,因为我做了很少的修改。 我的构建选项是-lcurl --lws2_32和-lwsock32(以消除成功编译后弹出的另一个错误)。
我认为我的链接是成功的,因为之前的成功构建,我添加了之前要求的所有dll。我该如何修复它,为什么它之前构建得很好?我应该打开编译器设置吗?唯一的一个是-Wall和-fexceptions
测试代码如下所示,直接来自其他网站,几乎没有任何修改。
#define CURL_STATICLIB
#include <stdio.h>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
#include <string>
#include <iostream>
size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
size_t written;
written = fwrite(ptr, size, nmemb, stream);
return written;
}
int main(void) {
CURL *curl;
FILE *fp;
CURLcode res;
std::cout << "Hello World";
char *url = "http://cnn.com";
char outfilename[FILENAME_MAX] = "C:\\bbb.txt";
curl = curl_easy_init();
if (curl) {
fp = fopen(outfilename,"wb");
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
fclose(fp);
}
return 0;
}
感谢您的帮助
更新:根据TimRau的建议,我将-lidn添加到链接器选项中。我现在得到以下错误:
||=== Build: Debug in Curl2 (compiler: GNU GCC Compiler) ===|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ssluse.o)|| undefined reference to `ERR_remove_thread_state'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_err2stringA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_set_optionA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_simple_bind_sA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_search_sA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_err2stringA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_err2stringA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_set_optionA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_initA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_get_dnA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_first_attributeA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_get_values_lenA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_memfreeA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_next_attributeA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_memfreeA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_memfreeA'|
C:\libs\curl-7.34.0-devel-mingw32\lib\libcurl.a(ldap.o)|| undefined reference to `_imp__ldap_memfreeA'|
||=== Build failed: 17 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
对于链接库,我有以下链接: C:\库\ libcurl_imp.lib C:\库\ libeay32.lib C:\库\ openldap.lib C:\库\ ssleay32.lib
我的链接器搜索目录中也有curl lib,curl包含编译器搜索目录。我根据http://www.learncpp.com/cpp-tutorial/a3-using-libraries-with-codeblocks/在线发现的说明将它们放入 因为它构建和工作一次,我认为这些设置是正确的,但我对这部分编程的理解极限。
更新2:添加
以消除第一个错误答案 0 :(得分:1)
您需要在编译命令的末尾添加-lidn -lwldap32
。