将libcurl + openssl静态链接到我的项目时链接器错误

时间:2011-08-09 15:53:11

标签: c++ curl openssl mingw libcurl

我正在尝试将libcurl(使用SSL)静态链接到我的项目中,但我遇到了很多链接器错误:

../lib/libcrypto.a(rand_win.o):rand_win.c:(.text+0xa9c): undefined reference to `CreateDCA@16'
../lib/libcrypto.a(rand_win.o):rand_win.c:(.text+0xaa9): undefined reference to `CreateCompatibleDC@4'
../lib/libcrypto.a(rand_win.o):rand_win.c:(.text+0xaba): undefined reference to `GetDeviceCaps@8'
../lib/libcrypto.a(rand_win.o):rand_win.c:(.text+0xaca): undefined reference to `GetDeviceCaps@8'
../lib/libcrypto.a(rand_win.o):rand_win.c:(.text+0xae0): undefined reference to `CreateCompatibleBitmap@12'
../lib/libcrypto.a(rand_win.o):rand_win.c:(.text+0xaee): undefined reference to `SelectObject@8'
../lib/libcrypto.a(rand_win.o):rand_win.c:(.text+0xb00): undefined reference to `GetObjectA@12'
../lib/libcrypto.a(rand_win.o):rand_win.c:(.text+0xb71): undefined reference to `BitBlt@36'
../lib/libcrypto.a(rand_win.o):rand_win.c:(.text+0xb7b): undefined reference to `GetBitmapBits@12'
../lib/libcrypto.a(rand_win.o):rand_win.c:(.text+0xbd2): undefined reference to `SelectObject@8'
../lib/libcrypto.a(rand_win.o):rand_win.c:(.text+0xbd9): undefined reference to `DeleteObject@4'
../lib/libcrypto.a(rand_win.o):rand_win.c:(.text+0xbe3): undefined reference to `DeleteDC@4'
../lib/libcrypto.a(rand_win.o):rand_win.c:(.text+0xbed): undefined reference to `DeleteDC@4'
../lib/librtmp.a(rtmp.o):rtmp.c:(.text+0x1b3b): undefined reference to `inet_addr@4'
../lib/librtmp.a(rtmp.o):rtmp.c:(.text+0x1ba4): undefined reference to `inet_addr@4'
../lib/librtmp.a(rtmp.o):rtmp.c:(.text+0x5d1e): undefined reference to `htonl@4'
../lib/librtmp.a(rtmp.o):rtmp.c:(.text+0x5eed): undefined reference to `ntohl@4'
../lib/librtmp.a(rtmp.o):rtmp.c:(.text+0x6f9a): undefined reference to `htonl@4'
../lib/librtmp.a(rtmp.o):rtmp.c:(.text+0x728d): undefined reference to `htonl@4'
../lib/librtmp.a(rtmp.o):rtmp.c:(.text+0x732c): undefined reference to `htonl@4'
../lib/librtmp.a(rtmp.o):rtmp.c:(.text+0x757f): undefined reference to `ntohl@4'
../lib/librtmp.a(rtmp.o):rtmp.c:(.text+0xb45): undefined reference to `timeGetTime@0'

以下是我下载的lib folfer中的文件列表。 enter image description here

我被告知我应该定义宏CURL_STATICLIB并在wsock32wldap32中进行链接。还有什么我应该做的吗?

我正在使用MinGW和Eclipse。

g++ -DCURL_STATICLIB -DUSE_LIBSSH2 -DHAVE_LIBSSH2 -DCURL_DISABLE_LDAP -DHAVE_LIBSSH2_H -DLIBSSH2_WIN32 -DLIBSSH2_LIBRARY -DUSE_SSLEAY -O0 -g3 -Wall -c -fmessage-length=0 -osrc\CURLDown.o ..\src\CURLDown.cpp

g++ -L../lib -oCURLDown.exe src\CURLDown.o -lcurl -lcrypto -lwsock32 -lwldap32 -leay32 -lidn -lrtmp -lssh2 -lz -lssl32 -lssl

2 个答案:

答案 0 :(得分:2)

对于那些在谷歌上搜索此答案的人来说,undefined reference to `CreateDCA@16'链接器错误正在寻找libgdi.a(只是-lgdi会这样做)。请记住,必须在 libcurl和openssl之后将包含在要链接的库列表中。

答案 1 :(得分:0)

g ++ -L ../ lib -oCURLDown.exe src \ CURLDown.o -lcurl -leay32 -lidn -lrtmp -lssh2 -lz -lssl32 -lcrypto

表示您确实没有指定所有库。也许你的makefile中有拼写错误? 我还看到对timeGetTime()的引用,它位于Winmm.lib中。

同样,libeay32和libcrypto似乎对谁应该定义什么产生误解。很可能有一个源文件由两个lib编译,只能由一个编译。