“cannot find -lcrypto -lssl” with OpenSSL on Windows with MinGW

回眸只為那壹抹淺笑 提交于 2021-02-08 03:48:07

问题


Trying out a c code for openssl, and this error showed up while compiling it in the command prompt.

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

now what should i do, please help.

Edit: Even these didn't help:

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\

回答1:


First off you need to compile openssl with mingw, the binaries you linked to were compiled with Visual Studio and are out of date and contain security vulnerabilites.

0.9.8 support is discontinued so I would advise using 1.0.1+.

Install ActivePerl and remove Stawberry Perl as it is not compatible with openssl.

Download the latest 1.0.1 source (openssl-1.0.1q.tar.gz) from: https://openssl.org/source/

Run the following in the msys console in the directory where you extracted the openssl source to:

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

and then run your compile command:

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

Edit: There are build problems on 0.9.8 with mingw so use 1.0.1 or higher and use ActivePerl not Strawberry Perl.




回答2:


I for instance did it differently.
I downloaded the compiled binaries from https://www.openssl.org/community/binaries.html.
Then just linked against them. Use -L for adding a search directory to the linker (explained here).

In the end I ended up with

g++ my_program.cpp -I"C:\Program Files (x86)\OpenSSL-Win32\include" -L"C:\Program Files (x86)\OpenSSL-Win32\lib\MinGW" -lssl -lcrypto

You seem to have it in C:/openssl/, so (and at the risk of stating the obvious) make the necessary changes for your environment.



来源:https://stackoverflow.com/questions/34752186/cannot-find-lcrypto-lssl-with-openssl-on-windows-with-mingw

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!