gpt4 book ai didi

c++ - 由解决方法 : c++ : boost_log : how does compiler choose st or mt 修复

转载 作者:太空宇宙 更新时间:2023-11-04 13:41:31 25 4
gpt4 key购买 nike

我的环境:solaris 5.10 gcc 4.8.2 boost 1.54

代码:

#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>


int main() {
BOOST_LOG_TRIVIAL(fatal) << "init " << filename << std::endl;
return 0;
}

编译选项和问题:

-bash-3.2$ g++ x.cc -lboost_log -lsocket  -lnsl -o x
Undefined first referenced
symbol in file
boost::log::v2s_st::aux::stream_provider<char>::allocate_compound(boost::log::v2s_st::record&) /var/tmp//ccPKqK2f.o
boost::log::v2s_st::aux::unhandled_exception_count() /var/tmp//ccPKqK2f.o
boost::log::v2s_st::record_view::public_data::destroy(boost::log::v2s_st::record_view::public_data const*) /var/tmp//ccPKqK2f.o
boost::log::v2s_st::core::open_record(boost::log::v2s_st::attribute_set const&) /var/tmp//ccPKqK2f.o
boost::log::v2s_st::trivial::logger::get() /var/tmp//ccPKqK2f.o
boost::log::v2s_st::core::get_logging_enabled() const /var/tmp//ccPKqK2f.o
boost::log::v2s_st::core::push_record_move(boost::log::v2s_st::record&) /var/tmp//ccPKqK2f.o
boost::log::v2s_st::aux::stream_provider<char>::release_compound(boost::log::v2s_st::aux::stream_provider<char>::stream_compound*) /var/tmp//ccPKqK2f.o
boost::log::v2s_st::sources::aux::get_severity_level() /var/tmp//ccPKqK2f.o
ld: fatal: symbol referencing errors. No output written to x
collect2: error: ld returned 1 exit status

但是

-bash-3.2$ nm -A /usr/local/lib/libboost_log.so | grep unhandled_exception_count
/usr/local/lib/libboost_log.so: [2277] | 735336| 24|FUNC |GLOB |0 |10 |_ZN5boost3log11v2_mt_posix3aux25unhandled_exception_countEv

我们可以看到有boost::log::v2s_**mt**::aux::unhandled_exception_count,但是没有boost::log::v2s_st::aux::unhandled_exception_count

我的问题是编译器如何选择在这种情况下使用哪一个?

我已阅读 http://www.boost.org/doc/libs/1_54_0/libs/log/doc/html/log/installation/config.html .但仍然不知道“无线程支持” 是什么意思。尝试使用 -lpthread 进行编译,但得到了同样的错误。

更新

-bash-3.2$ g++ x.cc  -lsocket  -lnsl -o x -pthread -lboost_log
Undefined first referenced
symbol in file
boost::log::v2s_mt_posix::core::open_record(boost::log::v2s_mt_posix::attribute_set const&) /var/tmp//ccZHBWis.o
icu::Collator::createInstance(icu::Locale const&, UErrorCode&) /usr/local/lib/gcc/sparc64-sun-solaris2.10/4.8.2/../../../libboost_regex.so.1.57.0
boost::log::v2s_mt_posix::aux::stream_provider<char>::allocate_compound(boost::log::v2s_mt_posix::record&) /var/tmp//ccZHBWis.o
boost::log::v2s_mt_posix::core::get_logging_enabled() const /var/tmp//ccZHBWis.o
boost::log::v2s_mt_posix::aux::unhandled_exception_count() /var/tmp//ccZHBWis.o
icu::Locale::Locale(icu::Locale const&) /usr/local/lib/gcc/sparc64-sun-solaris2.10/4.8.2/../../../libboost_regex.so.1.57.0
boost::log::v2s_mt_posix::record_view::public_data::destroy(boost::log::v2s_mt_posix::record_view::public_data const*) /var/tmp//ccZHBWis.o
boost::log::v2s_mt_posix::core::push_record_move(boost::log::v2s_mt_posix::record&) /var/tmp//ccZHBWis.o
icu::Locale::Locale() /usr/local/lib/gcc/sparc64-sun-solaris2.10/4.8.2/../../../libboost_regex.so.1.57.0
icu::Locale::~Locale() /usr/local/lib/gcc/sparc64-sun-solaris2.10/4.8.2/../../../libboost_regex.so.1.57.0
boost::log::v2s_mt_posix::aux::stream_provider<char>::release_compound(boost::log::v2s_mt_posix::aux::stream_provider<char>::stream_compound*) /var/tmp//ccZHBWis.o
boost::log::v2s_mt_posix::sources::aux::get_severity_level() /var/tmp//ccZHBWis.o
boost::log::v2s_mt_posix::trivial::logger::get() /var/tmp//ccZHBWis.o
ld: fatal: symbol referencing errors. No output written to x
collect2: error: ld returned 1 exit status

有了 pthread 标志,它开始使用“mt”,但它要求 v2s_mt_posix。但是我们的图书馆提供了v2s_mt_posix3

解决方法

-bash-3.2$ g++ x.cc  -lsocket  -lnsl -o x -pthread /usr/local/lib/libboost_log.a /usr/local/lib/libboost_log_setup.a  /usr/local/lib/libboost_thread.a /usr/local/lib/libboost_system.a -lrt
-bash-3.2$ ./x
[2014-12-17 02:15:55.082758] [0x10000000] [fatal] init

使用动态链接还是不行,原因不明

-bash-3.2$ g++ x.cc  -lsocket  -lnsl -o x -pthread -lboost_log -lboost_log_setup -lboost_thread -lboost_system -lrt
Undefined first referenced
symbol in file
boost::log::v2s_mt_posix::core::open_record(boost::log::v2s_mt_posix::attribute_set const&) /var/tmp//ccegh2wS.o
icu::Collator::createInstance(icu::Locale const&, UErrorCode&) /usr/local/lib/gcc/sparc64-sun-solaris2.10/4.8.2/../../../libboost_regex.so.1.57.0
boost::log::v2s_mt_posix::aux::stream_provider<char>::allocate_compound(boost::log::v2s_mt_posix::record&) /var/tmp//ccegh2wS.o
boost::log::v2s_mt_posix::core::get_logging_enabled() const /var/tmp//ccegh2wS.o
boost::log::v2s_mt_posix::aux::unhandled_exception_count() /var/tmp//ccegh2wS.o
icu::Locale::Locale(icu::Locale const&) /usr/local/lib/gcc/sparc64-sun-solaris2.10/4.8.2/../../../libboost_regex.so.1.57.0
boost::log::v2s_mt_posix::record_view::public_data::destroy(boost::log::v2s_mt_posix::record_view::public_data const*) /var/tmp//ccegh2wS.o
boost::log::v2s_mt_posix::core::push_record_move(boost::log::v2s_mt_posix::record&) /var/tmp//ccegh2wS.o
icu::Locale::Locale() /usr/local/lib/gcc/sparc64-sun-solaris2.10/4.8.2/../../../libboost_regex.so.1.57.0
icu::Locale::~Locale() /usr/local/lib/gcc/sparc64-sun-solaris2.10/4.8.2/../../../libboost_regex.so.1.57.0
boost::log::v2s_mt_posix::aux::stream_provider<char>::release_compound(boost::log::v2s_mt_posix::aux::stream_provider<char>::stream_compound*) /var/tmp//ccegh2wS.o
boost::log::v2s_mt_posix::sources::aux::get_severity_level() /var/tmp//ccegh2wS.o
boost::log::v2s_mt_posix::trivial::logger::get() /var/tmp//ccegh2wS.o
ld: fatal: symbol referencing errors. No output written to x
collect2: error: ld returned 1 exit status

最佳答案

你是对的,编译器确实根据 -pthread 标志选择 mt 或 st。就动态链接而言,构建 boost 时,您可能已经做了类似的事情:


./bootstrap.sh --with-libraries=log,program_options,regex,filesystem,system,thread --prefix=/opt/csw/
./b2 link=static define="_XOPEN_SOURCE=600"安装

link=static 仅构建静态库。

对我来说,这似乎会影响您的图书馆是否有 v2s 或 v2。看: http://www.boost.org/doc/libs/1_54_0/libs/log/doc/html/log/rationale/namespace_mangling.html

关于c++ - 由解决方法 : c++ : boost_log : how does compiler choose st or mt 修复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27504043/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com