jitesh pabla
jitesh pabla

Reputation: 61

"cannot find -lcrypto -lssl" with OpenSSL on Windows with MinGW

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\

Upvotes: 2

Views: 6331

Answers (2)

TrisT
TrisT

Reputation: 667

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.

Upvotes: 1

x64architecture
x64architecture

Reputation: 409

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.

Upvotes: 1

Related Questions