17

我正在编写一个使用 Boost 库的程序。我在链接和使用程序选项方面没有任何问题,但我似乎无法让 boost 日志正常工作。谁能告诉我我错过了什么?

果酱根.jam

using clang : : : <compileflags>-Isrc/main/headers <compileflags>-std=c++11 <compileflags>-stdlib=libc++ <linkflags>-std=c++11 <linkflags>-stdlib=libc++ ;
lib boost_program_options boost_log ;
exe foghorn : [ glob src/main/cpp/*.cpp ] boost_program_options boost_log ;

这是我得到的错误:

  "boost::log::v2s_mt_posix::record_view::public_data::destroy(boost::log::v2s_mt_posix::record_view::public_data const*)", referenced from:
      boost::log::v2s_mt_posix::record::reset() in main.o
  "boost::log::v2s_mt_posix::attribute_set::insert(boost::log::v2s_mt_posix::attribute_name, boost::log::v2s_mt_posix::attribute const&)", referenced from:
      boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>, boost::log::v2s_mt_posix::sources::single_thread_model>::add_attribute_unlocked(boost::log::v2s_mt_posix::attribute_name const&, boost::log::v2s_mt_posix::attribute const&) in main.o
      boost::log::v2s_mt_posix::aux::attribute_set_reference_proxy::operator=(boost::log::v2s_mt_posix::attribute const&) const in main.o
  "boost::log::v2s_mt_posix::attribute_set::attribute_set(boost::log::v2s_mt_posix::attribute_set const&)", referenced from:
      boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>, boost::log::v2s_mt_posix::sources::single_thread_model>::basic_logger(boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>, boost::log::v2s_mt_posix::sources::single_thread_model> const&) in main.o
  "boost::log::v2s_mt_posix::attribute_set::attribute_set()", referenced from:
      boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>, boost::log::v2s_mt_posix::sources::single_thread_model>::basic_logger() in main.o
  "boost::log::v2s_mt_posix::attribute_set::~attribute_set()", referenced from:
      boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>, boost::log::v2s_mt_posix::sources::single_thread_model>::~basic_logger() in main.o
  "boost::log::v2s_mt_posix::attribute_name::get_id_from_string(char const*)", referenced from:
      boost::log::v2s_mt_posix::attribute_name::attribute_name(char const*) in main.o
  "void boost::log::v2s_mt_posix::init_from_stream<char>(std::__1::basic_istream<char, std::__1::char_traits<char> >&)", referenced from:
      __ZL13gvLoggingInitPKc in main.o
  "boost::log::v2s_mt_posix::aux::this_thread::get_id()", referenced from:
      boost::log::v2s_mt_posix::attributes::current_thread_id::impl::dispatch(boost::log::v2s_mt_posix::type_dispatcher&) in main.o
      boost::log::v2s_mt_posix::attributes::current_thread_id::impl::detach_from_thread() in main.o
  "boost::log::v2s_mt_posix::aux::this_process::get_id()", referenced from:
      boost::log::v2s_mt_posix::attributes::current_process_id::current_process_id() in main.o
  "boost::log::v2s_mt_posix::aux::stream_provider<char>::release_compound(boost::log::v2s_mt_posix::aux::stream_provider<char>::stream_compound*)", referenced from:
      boost::log::v2s_mt_posix::aux::record_pump<boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel> >::auto_release::~auto_release() in main.o
  "boost::log::v2s_mt_posix::aux::stream_provider<char>::allocate_compound(boost::log::v2s_mt_posix::record&)", referenced from:
      boost::log::v2s_mt_posix::aux::record_pump<boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel> >::record_pump(boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>&, boost::log::v2s_mt_posix::record&) in main.o
  "boost::log::v2s_mt_posix::aux::get_process_name()", referenced from:
      boost::log::v2s_mt_posix::attributes::current_process_name::current_process_name() in main.o
  "boost::log::v2s_mt_posix::aux::once_block_sentry::commit()", referenced from:
      boost::log::v2s_mt_posix::aux::lazy_singleton<boost::log::v2s_mt_posix::sources::aux::logger_singleton<SLogger>, boost::shared_ptr<boost::log::v2s_mt_posix::sources::aux::logger_holder<boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel> > > >::get() in main.o
  "boost::log::v2s_mt_posix::aux::once_block_sentry::rollback()", referenced from:
      boost::log::v2s_mt_posix::aux::once_block_sentry::~once_block_sentry() in main.o
  "boost::log::v2s_mt_posix::aux::default_attribute_names::severity()", referenced from:
      boost::log::v2s_mt_posix::sources::basic_severity_logger<boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>, boost::log::v2s_mt_posix::sources::single_thread_model>, ESeverityLevel>::basic_severity_logger() in main.o
      boost::log::v2s_mt_posix::sources::basic_severity_logger<boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>, boost::log::v2s_mt_posix::sources::single_thread_model>, ESeverityLevel>::basic_severity_logger(boost::log::v2s_mt_posix::sources::basic_severity_logger<boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>, boost::log::v2s_mt_posix::sources::single_thread_model>, ESeverityLevel> const&) in main.o
  "boost::log::v2s_mt_posix::aux::unhandled_exception_count()", referenced from:
      boost::log::v2s_mt_posix::aux::record_pump<boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel> >::~record_pump() in main.o
      boost::log::v2s_mt_posix::aux::record_pump<boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel> >::record_pump(boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>&, boost::log::v2s_mt_posix::record&) in main.o
  "boost::log::v2s_mt_posix::aux::attach_attribute_name_info(boost::exception&, boost::log::v2s_mt_posix::attribute_name const&)", referenced from:
      boost::log::v2s_mt_posix::value_extractor<ESeverityLevel, boost::log::v2s_mt_posix::fallback_to_none, tag::severity>::operator()(boost::log::v2s_mt_posix::attribute_name const&, boost::log::v2s_mt_posix::attribute_value_set const&) const in main.o
  "boost::log::v2s_mt_posix::core::set_filter(boost::log::v2s_mt_posix::filter const&)", referenced from:
      __ZL13gvLoggingInitPKc in main.o
  "boost::log::v2s_mt_posix::core::open_record(boost::log::v2s_mt_posix::attribute_set const&)", referenced from:
      boost::log::v2s_mt_posix::record boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>, boost::log::v2s_mt_posix::sources::single_thread_model>::open_record_unlocked<boost::parameter::aux::tagged_argument<boost::log::v2s_mt_posix::keywords::tag::severity, ESeverityLevel const> >(boost::parameter::aux::tagged_argument<boost::log::v2s_mt_posix::keywords::tag::severity, ESeverityLevel const> const&) in main.o
  "boost::log::v2s_mt_posix::core::push_record_move(boost::log::v2s_mt_posix::record&)", referenced from:
      boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>, boost::log::v2s_mt_posix::sources::single_thread_model>::push_record_unlocked(boost::log::v2s_mt_posix::record&&) in main.o
  "boost::log::v2s_mt_posix::core::add_global_attribute(boost::log::v2s_mt_posix::attribute_name const&, boost::log::v2s_mt_posix::attribute const&)", referenced from:
      __ZL13gvLoggingInitPKc in main.o
  "boost::log::v2s_mt_posix::core::get()", referenced from:
      __ZL13gvLoggingInitPKc in main.o
      boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>, boost::log::v2s_mt_posix::sources::single_thread_model>::basic_logger() in main.o
      boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>, boost::log::v2s_mt_posix::sources::single_thread_model>::basic_logger(boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<ESeverityLevel>, boost::log::v2s_mt_posix::sources::single_thread_model> const&) in main.o
  "boost::log::v2s_mt_posix::sources::aux::global_storage::get_or_init(std::type_info const&, boost::shared_ptr<boost::log::v2s_mt_posix::sources::aux::logger_holder_base> (*)())", referenced from:
      boost::log::v2s_mt_posix::sources::aux::logger_singleton<SLogger>::init_instance() in main.o
  "boost::log::v2s_mt_posix::sources::aux::get_severity_level()", referenced from:
      boost::log::v2s_mt_posix::sources::aux::severity_level<ESeverityLevel>::set_value(ESeverityLevel) in main.o
      boost::log::v2s_mt_posix::sources::aux::severity_level<ESeverityLevel>::impl::dispatch(boost::log::v2s_mt_posix::type_dispatcher&) in main.o
      boost::log::v2s_mt_posix::sources::aux::severity_level<ESeverityLevel>::impl::detach_from_thread() in main.o
  "boost::log::v2s_mt_posix::sources::aux::throw_odr_violation(std::type_info const&, std::type_info const&, boost::log::v2s_mt_posix::sources::aux::logger_holder_base const&)", referenced from:
      boost::log::v2s_mt_posix::sources::aux::logger_singleton<SLogger>::init_instance() in main.o
  "boost::log::v2s_mt_posix::attribute::impl::operator delete(void*, unsigned long)", referenced from:
      boost::log::v2s_mt_posix::sources::aux::severity_level<ESeverityLevel>::severity_level() in main.o
      boost::log::v2s_mt_posix::sources::aux::severity_level<ESeverityLevel>::impl::~impl() in main.o
      boost::log::v2s_mt_posix::sources::aux::severity_level<ESeverityLevel>::impl::detach_from_thread() in main.o
      boost::log::v2s_mt_posix::attributes::attribute_value_impl<ESeverityLevel>::~attribute_value_impl() in main.o
      boost::log::v2s_mt_posix::attribute_value::impl::~impl() in main.o
      boost::log::v2s_mt_posix::attribute::impl::~impl() in main.o
      boost::log::v2s_mt_posix::attributes::current_thread_id::current_thread_id() in main.o
      ...
  "boost::log::v2s_mt_posix::attribute::impl::operator new(unsigned long)", referenced from:
      boost::log::v2s_mt_posix::sources::aux::severity_level<ESeverityLevel>::severity_level() in main.o
      boost::log::v2s_mt_posix::sources::aux::severity_level<ESeverityLevel>::impl::detach_from_thread() in main.o
      boost::log::v2s_mt_posix::attributes::current_thread_id::current_thread_id() in main.o
      boost::log::v2s_mt_posix::attributes::current_thread_id::impl::detach_from_thread() in main.o
      boost::log::v2s_mt_posix::attributes::constant<boost::log::v2s_mt_posix::aux::id<boost::log::v2s_mt_posix::aux::process> >::constant(boost::log::v2s_mt_posix::aux::id<boost::log::v2s_mt_posix::aux::process>&&) in main.o
      boost::log::v2s_mt_posix::attributes::constant<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::constant(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&&) in main.o
      boost::log::v2s_mt_posix::attributes::basic_clock<boost::log::v2s_mt_posix::attributes::local_time_traits>::basic_clock() in main.o
      ...
  "boost::system::system_category()", referenced from:
      ___cxx_global_var_init2 in main.o
  "boost::system::generic_category()", referenced from:
      ___cxx_global_var_init in main.o
      ___cxx_global_var_init1 in main.o
  "boost::log::v2s_mt_posix::attribute_value_set::end() const", referenced from:
      boost::log::v2s_mt_posix::value_extractor<ESeverityLevel, boost::log::v2s_mt_posix::fallback_to_none, tag::severity>::operator()(boost::log::v2s_mt_posix::attribute_name const&, boost::log::v2s_mt_posix::attribute_value_set const&) const in main.o
  "boost::log::v2s_mt_posix::attribute_value_set::find(boost::log::v2s_mt_posix::attribute_name) const", referenced from:
      boost::log::v2s_mt_posix::value_extractor<ESeverityLevel, boost::log::v2s_mt_posix::fallback_to_none, tag::severity>::operator()(boost::log::v2s_mt_posix::attribute_name const&, boost::log::v2s_mt_posix::attribute_value_set const&) const in main.o
  "boost::log::v2s_mt_posix::aux::once_block_sentry::enter_once_block() const", referenced from:
      boost::log::v2s_mt_posix::aux::once_block_sentry::executed() const in main.o
  "boost::log::v2s_mt_posix::core::get_logging_enabled() const", referenced from:
      __ZN5boost3log12v2s_mt_posix7sources22basic_composite_loggerIcNS2_15severity_loggerI14ESeverityLevelEENS2_19single_thread_modelENS2_8featuresIJNS2_8severityIS5_EEEEEE11open_recordINS_9parameter3aux15tagged_argumentINS1_8keywords3tag8severityEKS5_EEEENS1_6recordERKT_ in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

    "clang++"   -o "bin/clang-darwin-4.2.1/debug/foghorn" "bin/clang-darwin-4.2.1/debug/src/main/cpp/complement.o" "bin/clang-darwin-4.2.1/debug/src/main/cpp/degenerate.o" "bin/clang-darwin-4.2.1/debug/src/main/cpp/fastq.o" "bin/clang-darwin-4.2.1/debug/src/main/cpp/fastq_reader.o" "bin/clang-darwin-4.2.1/debug/src/main/cpp/interleave.o" "bin/clang-darwin-4.2.1/debug/src/main/cpp/interval_reader.o" "bin/clang-darwin-4.2.1/debug/src/main/cpp/interval_reader_test_tool.o" "bin/clang-darwin-4.2.1/debug/src/main/cpp/main.o" "bin/clang-darwin-4.2.1/debug/src/main/cpp/oligo_designer.o" "bin/clang-darwin-4.2.1/debug/src/main/cpp/reference_reader.o" "bin/clang-darwin-4.2.1/debug/src/main/cpp/reference_reader_test_tool.o" "bin/clang-darwin-4.2.1/debug/src/main/cpp/sequence_utils.o" "bin/clang-darwin-4.2.1/debug/src/main/cpp/tool.o"  -lboost_log -lboost_program_options  -g -std=c++11 -stdlib=libc++

...failed clang-darwin.link bin/clang-darwin-4.2.1/debug/foghorn...
...failed updating 1 target...
...updated 13 targets...
4

4 回答 4

16

我遇到了同样的问题,就我而言,问题是我只使用动态库编译了 boost,而忘记定义BOOST_ALL_DYN_LINK.

http://www.boost.org/doc/libs/1_54_0/libs/log/doc/html/log/rationale/namespace_mangling.html

作为测试,尝试编译

http://www.boost.org/doc/libs/1_54_0/libs/log/example/doc/tutorial_fmt_stream.cpp

#include <boost/log/support/date_time.hpp>应该添加,示例已损坏。)

并添加#define BOOST_LOG_DYN_LINK

我可以编译这个例子g++ tutorial_fmt_stream.cpp -Wall -L$BOOST/lib/ -I $BOOST/include/ -pthread -lboost_system -lboost_log_setup -lboost_log -lboost_date_time -lboost_thread -lrt -lboost_filesystem

于 2013-09-30T09:41:14.497 回答
5

如果您cmake用于管理您的提升,请不要忘记拥有类似的东西:

add_definitions(-DBOOST_LOG_DYN_LINK)

在你的CMakeLists.txt

于 2016-11-25T09:37:01.063 回答
2

我有同样的问题,这是一个复杂的链接路径。该消息显示正在尝试与静态库( ....v2s ...)链接,但链接器只给它动态库(因为它很愚蠢)。

您的 Boost 构建可能会同时生成.so.a文件,而当两者都存在时 gcc 会感到困惑。

我有一个CMake使用静态 Boost 库构建的库。如果您将此库链接到使用Makefile流的程序,则该程序还需要指定相同的静态 Boost 库。但是,-l链接器的选项是模糊的,而不是您的朋友。如果您将 Boost 构建为同时具有静态 (.a) 和动态 (.so) 输出,那么如果您只使用该-l选项,链接器将首先选择动态 (.so) 文件。

解决方法是不使用-Land-l选项来查找 Boost 静态库(因为它会失败),而是指定 Boost 库的完整路径。例如,

gcc .... -L/opt/boost_1.55/lib -lboost_log

改成

gcc .... /opt/boost_1.55/lib/libboost_log.a

另一种选择是为-staticgcc 指定单词,但这要求所有库都是静态的,如果您使用除了 boost 之外的任何东西(比如 librt.so 库),这可能不起作用。

于 2015-05-06T18:51:01.160 回答
1

如果您正在使用

void boost::log::v2s_mt_posix::init_from_stream<char>(std::basic_istream<char, std::char_traits<char> >&)

函数,那么你需要链接

libboost_log_setup.a
于 2017-09-07T07:55:21.130 回答