2

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\
jitesh pabla
  • 61
  • 2
  • 7
  • 2
    @iharob “Just use a different platform” is not a productive comment. – fuz Jan 12 '16 at 19:30
  • Possible duplicate of [Linking OpenSSL libraries to a program](http://stackoverflow.com/questions/4352573/linking-openssl-libraries-to-a-program) and [Can't link OpenSSL code](http://stackoverflow.com/q/11004314). – jww Jan 12 '16 at 19:39
  • @mikedu95 yes, I installed it from: http://stackoverflow.com/questions/11896304/openssl-is-not-recognized-as-an-internal-or-external-command – jitesh pabla Jan 12 '16 at 19:41
  • 1
    @iharob I neither like nor dislike you. I just dislike condescending comments like this. OP probably has a good reason to use Windows, demanding that OP uses a different platform is not helpful. – fuz Jan 12 '16 at 19:43
  • @jiteshpabla, Did you find the solution? I have the same problem... – Kimi Wu Nov 15 '18 at 04:55

2 Answers2

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.

x64architecture
  • 399
  • 1
  • 7
  • `$ perl Configure mingw --prefix=/c/openssl` - this command shows an error: `sh: perl: command not found` – jitesh pabla Jan 13 '16 at 05:23
  • I installed strawberry perl, but now i get this error: `Can't open perl script "Configure": No such file or directory` Edit: Solved; I just had to go to the openssl directory. – jitesh pabla Jan 13 '16 at 07:56
  • But now this error shows up: `$ gcc -o test test.c -Lc:\openssl\lib -lssl -lcrypto -Ic:\openssl\include test.c:8:25: fatal error: openssl/bio.h: No such file or directory #include ^ compilation terminated.` – jitesh pabla Jan 13 '16 at 08:06
1

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.

TrisT
  • 639
  • 6
  • 19