Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking ssl library

I am trying to link ssl library to my compilation command. I installed it via

sudo apt-get install libssl-dev

any my compiliaton command

g++ -Wall -pedantic -std=c++11 -lcrypto -lssl file.cpp

Yet it complains:

:(.text+0x19b): undefined reference to `SSL_library_init'
:(.text+0x1a0): undefined reference to `SSLv23_client_method'
:(.text+0x1a8): undefined reference to `SSL_CTX_new'
:(.text+0x1ff): undefined reference to `SSL_CTX_ctrl'
:(.text+0x20e): undefined reference to `SSL_new'
:(.text+0x26b): undefined reference to `SSL_set_fd'
:(.text+0x2b6): undefined reference to `SSL_get_peer_certificate'
:(.text+0x399): undefined reference to `PEM_write_X509'
:(.text+0x41d): undefined reference to `SSL_write'
(.text+0x511): undefined reference to `SSL_read'

All sources indicates that my linking is correct. I had same problem with crypto library but using installing command fixed it (seems like I didn't have it )

I am running Ubuntu.

like image 756
Darlyn Avatar asked Aug 01 '26 08:08

Darlyn


2 Answers

Note ssl should be placed before crypto. You may also try to add "/usr/local/ssl/lib" to linker search path:

g++ -Wall -pedantic -std=c++11 -lssl -lcrypto file.cpp -L/usr/local/ssl/lib
like image 93
Pavel P Avatar answered Aug 03 '26 22:08

Pavel P


You can try link it statically like that:

g++ -Wall -pedantic -std=c++11 /usr/lib64/libcrypto.a file.cpp

or

g++ -Wall -pedantic -std=c++11 /usr/lib/libcrypto++.a file.cpp

or

g++ -Wall -pedantic -std=c++11 /usr/lib/x86_64-linux-gnu/libcrypto.a file.cpp

or

g++ -Wall -pedantic -std=c++11 /usr/lib64/libcrypto.so file.cpp

Choose one of the above, depends on the location of the file on your device

like image 45
RoiHatam Avatar answered Aug 03 '26 23:08

RoiHatam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!