简体   繁体   English

boost/asio/ssl 抛出“未定义引用”错误

[英]boost/asio/ssl throwing “undefined reference” error

I am new to boost and am trying to compile the most basic program that includes boost/asio/ssl.我是 boost 新手,正在尝试编译包含 boost/asio/ssl 的最基本程序。 I am working on ubuntu 13.10 64bit and installed the latest boost like this:我正在 ubuntu 13.10 64bit 上工作并安装了最新的 boost,如下所示:

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.我在谷歌上搜索和搜索,我能找到的一些提示表明我使用了一些 boost 库标志。 So I did: g++ my_prog.cpp -o my_prog.bin -lboost_system -lboost_thread -lpthread所以我做了: 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 -li shove in):并且我一直收到相同的错误消息(无论输入多少 -li):

/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'对 `SSL_library_init' 的未定义引用

or:或者:

undefined reference to `ERR_reason_error_string'.对“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..).它编译得很好(即使没有 -lboost_system 和所有其他......)。

I spent a whole day on this and still can't for the life of me figure this out.我花了一整天的时间来解决这个问题,但仍然无法解决我的生活。 Any ideas guys?有什么想法吗?

在 vs2013 中,当我包含 <boost/asio/ssl.hpp> 时,我看到未解析的外部符号 _CONF_modules_upload 未解析的外部符号 _ERR_reason_error_string 我通过在链接器/附加依赖项中添加 libcrypto32MD.lib 解决了这些问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM