在Windows版Linux下与mingw32交叉编译时链接libcurl

woa*_*guy 5 c++ linux linker libcurl mingw-w64

我已经使用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
Run Code Online (Sandbox Code Playgroud)

但是,我无法使用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
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?。我无法摆脱这个。我知道这一定是个愚蠢的问题。

谢谢。

woa*_*guy 5

我可以通过指定-DCURL_STATICLIB以及链接其他一些依赖性来解决该问题。

x86_64-w64-mingw32-g++ main.cpp -o hello.exe -DCURL_STATICLIB -static -lstdc++ -lgcc -lpthread -lcurl -lwldap32 -lws2_32
Run Code Online (Sandbox Code Playgroud)