2011-08-15 50 views
1

我移植我在Linux上開發到Windows的應用程序和構建應用程序時,我有一些問題。在進行必要的代碼更改後,所有內容都編譯好了(並且在Visual Studio中構建爲調試版本時,運行沒有任何問題)。我需要在MinGW中構建它,並且當我嘗試將它鏈接到liboauth(我的項目也需要它)時鏈接器出錯。的MinGW /的libssl鏈接錯誤

的命令及其輸出如下:

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 

我都在庫路徑所需的庫,以及由於某種原因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 `[email protected]' 
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xeef): undefined reference to `[email protected]' 
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xf08): undefined reference to `[email protected]' 
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xf23): undefined reference to `[email protected]' 
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xf44): undefined reference to `[email protected]' 
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xf5b): undefined reference to `[email protected]' 
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0xf7e): undefined reference to `[email protected]' 
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0x1024): undefined reference to `[email protected]' 
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0x103b): undefined reference to `[email protected]' 
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0x10b0): undefined reference to `[email protected]' 
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0x10bb): undefined reference to `[email protected]' 
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0x10c8): undefined reference to `[email protected]' 
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libcrypto.a(rand_win.o):rand_win.c:(.text+0x10d5): undefined reference to `[email protected]' 
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

我想你正在使用的libssl和libcrypto的預編譯的版本,對不對?他們是建立在VS? –

+0

預編譯的libs crypto,ssl,curl,oauth和&jansson的靜態庫都是在MinGW下構建的。 –

+0

'gcc main.c -lcrypto -lgdi32'也適用於我,只需構建一個非常簡單的測試程序即可調用一些libcrypto函數。這是使用http://www.wittfella.com/openssl預構建的openssl庫,以及使用mingw msys編譯的庫,以及https://qt-project.org/wiki/Compiling-OpenSSL-with -MinGW – brianmearns

回答

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 
+0

很好的工作,它修復了它。用後續問題及其解決方案更新了我的問題。 –