MinGW / libssl链接错误

时间:2011-08-15 17:56:42

标签: c linker mingw linker-errors

我正在将我在Linux中开发的应用程序移植到Windows,并且在构建应用程序时遇到了一些问题。在进行必要的代码更改后,所有内容都编译得很好(当在Visual Studio中构建为调试版本时,运行没有任何问题)。我需要在MinGW中构建它,当我尝试将它与liboauth链接时我遇到了链接器错误,这也是我的项目所必需的。

命令及其输出如下:

gcc application.o service.o util.o json.o api.o -L/usr/local/lib -lcrypto -lssl -lcurl -ljansson -loauth -Wl -o application

C:/MinGW/msys/1.0/local/lib/liboauth.a(liboauth_la-hash.o): In function `oauth_sign_hmac_sha1_raw':
c:\lib\liboauth-0.9.4\src/hash.c:314: undefined reference to `EVP_sha1'
c:\lib\liboauth-0.9.4\src/hash.c:314: undefined reference to `HMAC'
C:/MinGW/msys/1.0/local/lib/liboauth.a(liboauth_la-hash.o): In function `oauth_sign_rsa_sha1':
c:\lib\liboauth-0.9.4\src/hash.c:334: undefined reference to `BIO_new_mem_buf'
c:\lib\liboauth-0.9.4\src/hash.c:335: undefined reference to `PEM_read_bio_PrivateKey'
c:\lib\liboauth-0.9.4\src/hash.c:336: undefined reference to `BIO_free'
c:\lib\liboauth-0.9.4\src/hash.c:343: undefined reference to `EVP_PKEY_size'
c:\lib\liboauth-0.9.4\src/hash.c:346: undefined reference to `EVP_sha1'
c:\lib\liboauth-0.9.4\src/hash.c:346: undefined reference to `EVP_DigestInit'
c:\lib\liboauth-0.9.4\src/hash.c:347: undefined reference to `EVP_DigestUpdate'
c:\lib\liboauth-0.9.4\src/hash.c:348: undefined reference to `EVP_SignFinal'
c:\lib\liboauth-0.9.4\src/hash.c:352: undefined reference to `CRYPTO_free'
c:\lib\liboauth-0.9.4\src/hash.c:353: undefined reference to `EVP_PKEY_free'
C:/MinGW/msys/1.0/local/lib/liboauth.a(liboauth_la-hash.o): In function `oauth_verify_rsa_sha1':
c:\lib\liboauth-0.9.4\src/hash.c:367: undefined reference to `BIO_new_mem_buf'
c:\lib\liboauth-0.9.4\src/hash.c:368: undefined reference to `PEM_read_bio_X509'
c:\lib\liboauth-0.9.4\src/hash.c:370: undefined reference to `X509_get_pubkey'
c:\lib\liboauth-0.9.4\src/hash.c:371: undefined reference to `X509_free'
c:\lib\liboauth-0.9.4\src/hash.c:375: undefined reference to `BIO_free'
c:\lib\liboauth-0.9.4\src/hash.c:384: undefined reference to `EVP_sha1'
c:\lib\liboauth-0.9.4\src/hash.c:384: undefined reference to `EVP_DigestInit'
c:\lib\liboauth-0.9.4\src/hash.c:385: undefined reference to `EVP_DigestUpdate'
c:\lib\liboauth-0.9.4\src/hash.c:386: undefined reference to `EVP_VerifyFinal'
c:\lib\liboauth-0.9.4\src/hash.c:387: undefined reference to `EVP_MD_CTX_cleanup'
c:\lib\liboauth-0.9.4\src/hash.c:388: undefined reference to `EVP_PKEY_free'
c:\lib\liboauth-0.9.4\src/hash.c:373: undefined reference to `PEM_read_bio_PUBKEY'
C:/MinGW/msys/1.0/local/lib/liboauth.a(liboauth_la-hash.o): In function `oauth_body_hash_file':
c:\lib\liboauth-0.9.4\src/hash.c:405: undefined reference to `EVP_MD_CTX_init'
c:\lib\liboauth-0.9.4\src/hash.c:406: undefined reference to `EVP_sha1'
c:\lib\liboauth-0.9.4\src/hash.c:406: undefined reference to `EVP_DigestInit'
c:\lib\liboauth-0.9.4\src/hash.c:408: undefined reference to `EVP_DigestUpdate'
c:\lib\liboauth-0.9.4\src/hash.c:412: undefined reference to `EVP_sha1'
c:\lib\liboauth-0.9.4\src/hash.c:412: undefined reference to `EVP_MD_size'
c:\lib\liboauth-0.9.4\src/hash.c:413: undefined reference to `EVP_DigestFinal'
c:\lib\liboauth-0.9.4\src/hash.c:414: undefined reference to `EVP_MD_CTX_cleanup'
C:/MinGW/msys/1.0/local/lib/liboauth.a(liboauth_la-hash.o): In function `oauth_body_hash_data':
c:\lib\liboauth-0.9.4\src/hash.c:422: undefined reference to `EVP_sha1'
c:\lib\liboauth-0.9.4\src/hash.c:422: undefined reference to `EVP_MD_size'
c:\lib\liboauth-0.9.4\src/hash.c:423: undefined reference to `EVP_MD_CTX_init'
c:\lib\liboauth-0.9.4\src/hash.c:424: undefined reference to `EVP_sha1'
c:\lib\liboauth-0.9.4\src/hash.c:424: undefined reference to `EVP_DigestInit'
c:\lib\liboauth-0.9.4\src/hash.c:425: undefined reference to `EVP_DigestUpdate'
c:\lib\liboauth-0.9.4\src/hash.c:426: undefined reference to `EVP_DigestFinal'
c:\lib\liboauth-0.9.4\src/hash.c:427: undefined reference to `EVP_MD_CTX_cleanup'
collect2: ld returned 1 exit status
make: *** [montools] Error 1

我在lib路径中拥有所有必需的库,并且由于某种原因,liboauth无法找到对libssl和libcrypto的引用。这一切都在Linux中构建良好。有什么想法吗?

更新

根据回复,我更新了我的链接器命令,以便以不同的顺序链接库。我的新命令如下:

gcc -o application application.o service.o util.o json.o api.o -Lc:/mingw/msys/1.0/local/lib -loauth -ljansson -lcurl -lssl -lcrypto

这解决了上一个问题并提出了一组新的链接器错误:

gcc -o application application.o service.o util.o json.o api.o -Lc:/mingw/msys/1.0/local/lib -loauth -ljansson -lcurl -lssl -lcrypto 
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xee0): undefined reference to `CreateDCA@16'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xeef): undefined reference to `CreateCompatibleDC@4'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xf08): undefined reference to `GetDeviceCaps@8'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xf23): undefined reference to `GetDeviceCaps@8'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xf44): undefined reference to `CreateCompatibleBitmap@12'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xf5b): undefined reference to `SelectObject@8'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xf7e): undefined reference to `GetObjectA@12'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0x1024): undefined reference to `BitBlt@36'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0x103b): undefined reference to `GetBitmapBits@12'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0x10b0): undefined reference to `SelectObject@8'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0x10bb): undefined reference to `DeleteObject@4'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0x10c8): undefined reference to `DeleteDC@4'
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0x10d5): undefined reference to `DeleteDC@4'
collect2: ld returned 1 exit status
make: *** [montools] Error 1

快速谷歌搜索返回我还应该链接到gdi32库(用于与我的任务无关的目的。链接器的最终命令如下:

gcc -o application application.o service.o util.o json.o api.o -Lc:/mingw/msys/1.0/local/lib -loauth -ljansson -lcurl -lssl -lcrypto -lgdi32

1 个答案:

答案 0 :(得分:2)

试试这个:

gcc -o application application.o service.o util.o json.o api.o -Lc:/mingw/msys/1.0/local/lib -loauth -ljansson -lcurl -lssl -lcrypto