2016-01-12 65 views
0

嘗試openssl的c代碼,並在命令提示符下編譯時出現此錯誤。「在Windows上使用OpenSSL時找不到-lcrypto -lssl」(使用MinGW)

c:\openssl>gcc -lssl -lcrypto -o test test.c -IC:\openssl\include\ 
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lssl 
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lcrypto 
collect2.exe: error: ld returned 1 exit status 

現在我該怎麼做,請幫助。

編輯: 即使這些並沒有幫助:

c:\openssl>gcc -o test test.c -lssl -lcrypto -Ic:\openssl\include\ 
c:\openssl>gcc -o test test.c -I c:\openssl\include\ -L c:\openssl\lib -lssl -lcrypto 
c:\openssl>gcc -o test test.c -Lc:\openssl\lib -lssl -lcrypto -Ic:\openssl\include\ 
+2

@iharob「只是使用不同的平臺」不是一個有生產力的評論。 – fuz

+0

[將OpenSSL庫鏈接到程序]可能的重複(http://stackoverflow.com/questions/4352573/linking-openssl-libraries-to-a-program)和[無法鏈接OpenSSL代碼](http:///stackoverflow.com/q/11004314)。 – jww

+0

@ mikedu95是的,我安裝它:http://stackoverflow.com/questions/11896304/openssl-is-not-recognized-as-an-internal-or-external-command –

回答

0

首先你需要編譯MinGW的OpenSSL的,你鏈接的二進制文件與Visual Studio進行了彙編和已經過時的和包含安全vulnerabilites 。

0.9.8支持已停止,所以我會建議使用1.0.1+。

安裝ActivePerl並刪除Stawberry Perl,因爲它與openssl不兼容。

下載從最新的1.0.1源(的OpenSSL 1.0.1q.tar.gz):

https://openssl.org/source/

運行在該目錄中的MSYS控制檯,您提取的OpenSSL源以下

$ perl Configure mingw --prefix=/c/openssl 
$ make depend 
$ make 
$ make install 

,然後運行編譯命令:

gcc -o test test.c -Lc:\openssl\lib -lssl -lcrypto -Ic:\openssl\include\ 

編輯: 有建立在0.9.8問題的MinGW所以使用1.0.1或更高,並使用ActivePerl而不是Strawberry Perl。

+0

'$ perl配置mingw --prefix =/c/openssl' - 這個命令顯示錯誤:'sh:perl:command not found' –

+0

因此安裝它和/或指向env。變量到perl bin。 –

+0

我安裝了草莓Perl,但現在我得到這個錯誤:'無法打開Perl腳本「配置」:沒有這樣的文件或目錄「編輯:已解決;我只需要去openssl目錄。 –

相關問題