【发布时间】:2015-07-21 08:52:50
【问题描述】:
我已经使用 mingw32 编译了 libcurl,并正在尝试将它与我的程序链接,该程序使用 mingw32 用于我的 Linux 机器上的 Windows 系统。
我输出了文件,libcurl-4.dll libcurl.a libcurl.la libcurl.lai。
我已将它们包含在我的 mingw32 libs 文件夹中:/usr/x86_64-w64-mingw32/lib
我能够找到一些关于与 libstdc++ 和 libgcc 链接的其他主题,以在执行时注意依赖错误,但在尝试添加 libcurl.a 时它将无法编译。
我使用了以下内容:
$ x86_64-w64-mingw32-g++ main.cpp -o hello.exe -static-libgcc -static-libstdc++ -static "/usr/x86_64-w64-mingw32/lib/libcurl.a" -lpthread
但是,我无法让它使用 libcurl.a 并且继续收到这些错误。
/tmp/ccIceRus.o:main.cpp:(.text+0xde): undefined reference to `__imp_curl_easy_init'
/tmp/ccIceRus.o:main.cpp:(.text+0x106): undefined reference to `__imp_curl_easy_setopt'
/tmp/ccIceRus.o:main.cpp:(.text+0x122): undefined reference to `__imp_curl_easy_setopt'
/tmp/ccIceRus.o:main.cpp:(.text+0x13e): undefined reference to `__imp_curl_easy_setopt'
/tmp/ccIceRus.o:main.cpp:(.text+0x159): undefined reference to `__imp_curl_easy_setopt'
/tmp/ccIceRus.o:main.cpp:(.text+0x169): undefined reference to `__imp_curl_easy_perform'
/tmp/ccIceRus.o:main.cpp:(.text+0x180): undefined reference to `__imp_curl_easy_strerror'
/tmp/ccIceRus.o:main.cpp:(.text+0x197): undefined reference to `__imp_curl_easy_cleanup'
/usr/bin/x86_64-w64-mingw32-ld: /tmp/ccIceRus.o: bad reloc address 0x80 in section `.xdata'
collect2: error: ld returned 1 exit status
我做错了什么?我无法克服这一点。我知道这一定是个愚蠢的问题。
谢谢。
【问题讨论】:
-
无需提及
static这个词,因为您使用的是目标文件存档的完整路径——这无论如何都不是动态库。试试这个方法:$ x86_64-w64-mingw32-g++ main.cpp "/usr/x86_64-w64-mingw32/lib/libcurl.a" -o hello.exe -static-libgcc -static-libstdc++ -lpthread -
如果启用了共享库,这将起作用,但是,如果它们仅使用静态“存档”库,则运气不佳。
标签: c++ linux linker libcurl mingw-w64