Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use OpenSSL with GCC?

Tags:

I'm trying to use openssl in a gcc program but it isn't working.

g++ server.cpp /usr/lib/libssl.a -o server 

gives an error message, as does anything with the -l option. What must I type on the command line to link with openssl? The file /usr/lib/libssl.a exists, but nevertheless I still get the linker error no such function MD5() exists.

like image 803
Jondo Zaro Avatar asked Dec 12 '09 16:12

Jondo Zaro


People also ask

Where is OpenSSL include Linux?

The standard location of the development libs is /usr/include/openssl . The only shared objects for openssl are in /usr/lib/i386-linux-gnu/openssl-1.0. 0/engines/ .

Is OpenSSL AC library?

The openssl library is a C library and if VS is not able to compile C code.


2 Answers

Without knowing the exact errors you are seeing, it is difficult to provide an exact solution. Here is my best attempt.

From the information you provided, it sounds as though the linker is failing because it cannot find a reference to the md5 function in libssl.a. I believe this function is actually in libcrypto so you may need to specify this library as well.

g++ server.cpp -L/usr/lib -lssl -lcrypto -o server

like image 92
jschmier Avatar answered Sep 21 '22 01:09

jschmier


You or others may find this article developerWorks article helpful.

  • Secure programming with the OpenSSL API
    • https://developer.ibm.com/technologies/linux/tutorials/l-openssl

It describes most things you need to know to get off the ground with OpenSSL and C/C++. If you find you are following most of the same steps, it might help you see what needs doing.

Good luck.


update

  • revised link: https://developer.ibm.com/technologies/linux/tutorials/l-openssl
    • Which has been shuffled around
  • original link: http://www.ibm.com/developerworks/linux/library/l-openssl.html
    • Which now goes to a digest page including the article.

Note: keeping both links because they be used to find new discoveries.

like image 21
will Avatar answered Sep 19 '22 01:09

will