boost/asio/ssl throwing "undefined reference" error
Asked Answered
C

1

8

I am new to boost and am trying to compile the most basic program that includes boost/asio/ssl. I am working on ubuntu 13.10 64bit and installed the latest boost like this:

sudo apt-get install boost-all-dev

Here is the magnificent code I am trying to compile:

#include <stdio.h>
#include <boost/asio/ssl/stream.hpp>

int main(){
   printf("Hi\n");
   return 0;
}

I googled and googled and the few hints I was able to find suggests I use some boost library flags. So I did: g++ my_prog.cpp -o my_prog.bin -lboost_system -lboost_thread -lpthread

and all the time I get the same error message (no matter how many -l i shove in):

/tmp/cci6dJdZ.o: In function `boost::asio::ssl::detail::openssl_init_base::do_init::do_init()':
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initC2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initC5Ev]+0x2c): undefined reference to `SSL_library_init'
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initC2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initC5Ev]+0x31): undefined reference to `SSL_load_error_strings'
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initC2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initC5Ev]+0x36): undefined reference to `OPENSSL_add_all_algorithms_noconf'
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initC2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initC5Ev]+0x47): undefined reference to `CRYPTO_num_locks'
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initC2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initC5Ev]+0xcc): undefined reference to `CRYPTO_set_locking_callback'
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initC2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initC5Ev]+0xd6): undefined reference to `CRYPTO_set_id_callback'
/tmp/cci6dJdZ.o: In function `boost::asio::ssl::detail::openssl_init_base::do_init::~do_init()':
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initD2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initD5Ev]+0x13): undefined reference to `CRYPTO_set_id_callback'
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initD2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initD5Ev]+0x1d): undefined reference to `CRYPTO_set_locking_callback'
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initD2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initD5Ev]+0x22): undefined reference to `ERR_free_strings'
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initD2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initD5Ev]+0x2c): undefined reference to `ERR_remove_state'
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initD2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initD5Ev]+0x31): undefined reference to `EVP_cleanup'
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initD2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initD5Ev]+0x36): undefined reference to `CRYPTO_cleanup_all_ex_data'
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initD2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initD5Ev]+0x40): undefined reference to `CONF_modules_unload'
my_prog.cpp:(.text._ZN5boost4asio3ssl6detail17openssl_init_base7do_initD2Ev[_ZN5boost4asio3ssl6detail17openssl_init_base7do_initD5Ev]+0x45): undefined reference to `ENGINE_cleanup'
/tmp/cci6dJdZ.o: In function `boost::asio::error::detail::ssl_category::message(int) const':
my_prog.cpp:(.text._ZNK5boost4asio5error6detail12ssl_category7messageEi[_ZNK5boost4asio5error6detail12ssl_category7messageEi]+0x1d): undefined reference to `ERR_reason_error_string'
collect2: error: ld returned 1 exit status

Or in short: it complaining about missing symbols like:

undefined reference to `SSL_library_init'

or:

undefined reference to `ERR_reason_error_string'.

Another funny fact is that if I change the include:

#include <boost/asio/ssl/stream.hpp>

for example to

#include <boost/asio/ssl/stream_base.hpp>

it compiles just fine (even without -lboost_system and all others..).

I spent a whole day on this and still can't for the life of me figure this out. Any ideas guys?

Cavill answered 3/2, 2014 at 15:41 Comment(3)
add: -lcrypto -lssl - your boost is built with a dependency on these librariesWreath
Thanks man, that's really compiled the code above, But I have an old code that was written with libboost1.42 and it's make file contains (among other) the flag -lcrypt (instead of crypto). If I change it to crypto it compiles but doesn't work. Can you explain the differences between crypt and crypto and what can I do in my situation? Thanks a lot!Cavill
@Petesh it's not Boost that was built with OpenSSL dependency, but the user program. @Michael, libcrypt is a part of GLIBC, while libcrypto is a part of OpenSSL. If your old code uses Boost.Asio parts that depend on libcrypto, you should link with it. But maybe you attempt to compile with a newer Boost.Asio version, while your code actually expects an older one?Spoof
V
2

In vs2013, when I include <boost/asio/ssl.hpp> I see unresolved external symbol _CONF_modules_upload unresolved external symbol _ERR_reason_error_string I solved those issues by adding libcrypto32MD.lib in Linker/Additional Dependencies

Vullo answered 3/9, 2020 at 7:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.