【问题标题】:How do I solve these libcurl linking errors?如何解决这些 libcurl 链接错误?
【发布时间】:2011-07-25 23:58:41
【问题描述】:
[Administrator@windows ~]$ g++ client.cpp -lcurl -o client.exe
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0x23): undefined reference to `_imp__curl_global_init'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0x5f): undefined reference to `_imp__curl_formadd'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0x9b): undefined reference to `_imp__curl_formadd'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0xa2): undefined reference to `_imp__curl_easy_init'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0xc8): undefined reference to `_imp__curl_easy_setopt'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0xe4): undefined reference to `_imp__curl_easy_setopt'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0xf1): undefined reference to `_imp__curl_easy_perform'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0x101): undefined reference to `_imp__curl_easy_cleanup'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0x10e): undefined reference to `_imp__curl_formfree'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0x11b): undefined reference to `_imp__curl_slist_free_all'
collect2: ld returned 1 exit status

我在 linux 上没有这个问题,所以我不知道为什么会在 windows 上发生这种情况。我已经用 google 搜索过了,除了邮件列表存档之外没有找到任何东西,并回复说“google it”。

我正在使用 mingw。我在构建 libcurl 时确实收到了一些链接器警告,但它们似乎与 ssl 相关,而且我不知道这是否很重要,因为它构建时没有错误。

*** Warning: linker path does not have real file for library -lssl.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have
*** because I did check the linker path looking for a file starting
*** with libssl and none of the candidates passed a file format test
*** using a file magic. Last file checked: /ssl/lib/libssl.a

*** Warning: linker path does not have real file for library -lcrypto.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have
*** because I did check the linker path looking for a file starting
*** with libcrypto and none of the candidates passed a file format test
*** using a file magic. Last file checked: /ssl/lib/libcrypto.a

*** Warning: linker path does not have real file for library -lz.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have
*** because I did check the linker path looking for a file starting
*** with libz and none of the candidates passed a file format test
*** using a file magic. Last file checked: /mingw/lib//libz.a
*** The inter-library dependencies that have been dropped here will be
*** automatically added whenever a program is linked with this library
*** or is declared to -dlopen it.

*** Since this library must not contain undefined symbols,
*** because either the platform does not support them or
*** it was explicitly requested with -no-undefined,
*** libtool will only create a static version of it.

【问题讨论】:

    标签: c++ windows curl linker mingw


    【解决方案1】:

    通过添加选项-lcurl.dll,我能够在 Windows (mingw win32) 上避免这些 curl 链接错误。我的情况不需要-DCURL_STATICLIB

    我的构建在 mingw/lib 文件夹中有两个 libcurl 文件:libcurl.a and libcurl.dll.a

    【讨论】:

    • 感谢解决我的问题 g++ 的面包屑:Code::Blocks > Settings > Compiler > Linker settings > Add > lib\libcurldll.a && lib\libcurl.a
    【解决方案2】:

    Libtool 只构建了一个静态 libcurl,而不是一个动态库。您的标头正在寻找动态 libcurl。这可能不是 libcurl 的错,因为我可以在支持 __declspec(dllimport)__declspec(dllexport) 的标头中看到代码(这是软件包作者知道什么是什么的好兆头。

    技术细节:see this answer regarding libssh

    解决方案:使用-DCURL_STATICLIB编译。

    【讨论】:

    • 嗯。我认为 libcurl 构建了静态和动态的。我试过 -DCURL_STATICLIB 但现在我收到数百个链接器错误,说未定义对 WSAStartup@8、_imp__ares_library_init、ntohs@4、getsockopt@20 等的引用。
    • 您没有在任何依赖库中进行链接。您将需要(至少)-lwinsock2` 以及用于其他库的 -l 标志(它看起来像 OpenSSL,可能还有一两个其他库)。
    【解决方案3】:

    在使用带有 mingw 的 netbeans 7.1 时遇到了同样的问题。从属性中,添加库 libcurl.dll.a 的链接器为我解决了这个问题。

    在我运行 mingw make 后,该文件位于 curl-7.28.1\lib.libs 下。

    【讨论】:

      【解决方案4】:

      我在不同的项目中遇到了类似的错误(使用 libz 和 libsqlite)。 它由 GNU libtool 脚本生成。

      在我的情况下,原因是缺少这些库 (.la ?) 的某些文件,或者可能是这些库的 libz.dll.a 变体。

      要让 automake/autoconf 构建 ./configure --prefix=... ; make 所需的所有文件,您必须在同一 MSYS 下构建 zlibcryptossl 以及 configuremake。 cmake 或自定义 makefile 构建通常不能作为共享库自动工具构建的依赖项。

      另一个也是最简单的选择是使用 cmake (https://github.com/bagder/curl.git) 构建动态 curl

      【讨论】:

        猜你喜欢
        • 2011-10-02
        • 1970-01-01
        • 2023-03-08
        • 1970-01-01
        • 2010-11-01
        • 2014-02-19
        • 1970-01-01
        • 1970-01-01
        • 2011-05-25
        相关资源
        最近更新 更多