Undefined reference to `boost :: log_mt_posix :: basic_attribute_set <char> :: ~ basic_attribute_set () '

Newbie question ... I am trying to launch Boost for the first time because I want to test the drive in the Boost Log library. I built this test program ...

#include <boost/log/trivial.hpp> #include <iostream> int fibonacci(int num) { int i; int a = 1; int b = 1; for (i = 2; i <= num; ++i) { BOOST_LOG_TRIVIAL(info) << "Iteration " << i << " (a = " << a << ", b = " << b << ")..."; b = a + b; a = b - a; } return a; } int main() { std::cout << "8th fibonacci number: " << fibonacci(8) << std::endl; return 0; } 

Compile data:

 **** Build of configuration Debug for project LoggingCpp **** make all Building file: ../main.cpp Invoking: GCC C++ Compiler g++ -O0 -g3 -Wall -c -fmessage-length=0 -lpthread -MMD -MP -MF"main.d" -MT"main.d" -o"main.o" "../main.cpp" Finished building: ../main.cpp Building target: LoggingCpp Invoking: GCC C++ Linker g++ -lpthread -o"LoggingCpp" ./main.o ./main.o: In function `~basic_logger': /usr/include/boost/log/sources/basic_logger.hpp:90: undefined reference to `boost::log_mt_posix::basic_attribute_set<char>::~basic_attribute_set()' ./main.o: In function `boost::log_mt_posix::trivial::logger::construct_logger()': /usr/include/boost/log/trivial.hpp:102: undefined reference to `boost::log_mt_posix::trivial::aux::init()' ./main.o: In function `void boost::call_once<void (*)()>(boost::once_flag&, void (*)())': /usr/include/boost/thread/pthread/once.hpp:51: undefined reference to `boost::detail::get_once_per_thread_epoch()' /usr/include/boost/thread/pthread/once.hpp:55: undefined reference to `boost::detail::once_epoch_mutex' /usr/include/boost/thread/pthread/once.hpp:66: undefined reference to `boost::detail::once_epoch_mutex' /usr/include/boost/thread/pthread/once.hpp:77: undefined reference to `boost::detail::once_global_epoch' /usr/include/boost/thread/pthread/once.hpp:77: undefined reference to `boost::detail::once_global_epoch' /usr/include/boost/thread/pthread/once.hpp:77: undefined reference to `boost::detail::once_global_epoch' /usr/include/boost/thread/pthread/once.hpp:78: undefined reference to `boost::detail::once_epoch_cv' /usr/include/boost/thread/pthread/once.hpp:84: undefined reference to `boost::detail::once_epoch_mutex' /usr/include/boost/thread/pthread/once.hpp:84: undefined reference to `boost::detail::once_epoch_cv' /usr/include/boost/thread/pthread/once.hpp:88: undefined reference to `boost::detail::once_global_epoch' /usr/include/boost/thread/pthread/once.hpp:73: undefined reference to `boost::detail::once_epoch_cv' ./main.o: In function `record_pump': /usr/include/boost/log/sources/record_ostream.hpp:293: undefined reference to `boost::log_mt_posix::aux::stream_provider<char>::allocate_compound(boost::log_mt_posix::basic_record<char> const&)' ./main.o: In function `~auto_release': /usr/include/boost/log/sources/record_ostream.hpp:280: undefined reference to `boost::log_mt_posix::aux::stream_provider<char>::release_compound(boost::log_mt_posix::aux::stream_provider<char>::stream_compound*)' ./main.o: In function `boost::log_mt_posix::sources::aux::logger_singleton<boost::log_mt_posix::trivial::logger>::init_instance()': /usr/include/boost/log/sources/global_logger_storage.hpp:126: undefined reference to `boost::log_mt_posix::sources::aux::global_storage<char>::get_or_init(std::type_info const&, boost::function0<boost::shared_ptr<boost::log_mt_posix::sources::aux::logger_holder_base> > const&)' /usr/include/boost/log/sources/global_logger_storage.hpp:147: undefined reference to `boost::log_mt_posix::odr_violation::throw_(char const*, unsigned long, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' ./main.o: In function `boost::log_mt_posix::sources::aux::severity_level<boost::log_mt_posix::trivial::severity_level>::set_value(boost::log_mt_posix::trivial::severity_level)': /usr/include/boost/log/sources/severity_feature.hpp:95: undefined reference to `boost::log_mt_posix::sources::aux::set_severity_level(int)' ./main.o: In function `boost::log_mt_posix::basic_record<char> boost::log_mt_posix::sources::basic_logger<char, boost::log_mt_posix::sources::severity_logger_mt<boost::log_mt_posix::trivial::severity_level>, boost::log_mt_posix::sources::multi_thread_model<boost::log_mt_posix::aux::light_rw_mutex> >::open_record_unlocked<boost::parameter::aux::tagged_argument<boost::log_mt_posix::keywords::tag::severity, boost::log_mt_posix::trivial::severity_level const> >(boost::parameter::aux::tagged_argument<boost::log_mt_posix::keywords::tag::severity, boost::log_mt_posix::trivial::severity_level const> const&)': /usr/include/boost/log/sources/basic_logger.hpp:269: undefined reference to `boost::log_mt_posix::basic_core<char>::open_record(boost::log_mt_posix::basic_attribute_set<char> const&)' ./main.o: In function `boost::log_mt_posix::sources::basic_logger<char, boost::log_mt_posix::sources::severity_logger_mt<boost::log_mt_posix::trivial::severity_level>, boost::log_mt_posix::sources::multi_thread_model<boost::log_mt_posix::aux::light_rw_mutex> >::push_record_unlocked(boost::log_mt_posix::basic_record<char> const&)': /usr/include/boost/log/sources/basic_logger.hpp:280: undefined reference to `boost::log_mt_posix::basic_core<char>::push_record(boost::log_mt_posix::basic_record<char> const&)' ./main.o: In function `basic_logger<boost::parameter::aux::tagged_argument<boost::log_mt_posix::keywords::tag::severity, const boost::log_mt_posix::trivial::severity_level> >': /usr/include/boost/log/sources/basic_logger.hpp:145: undefined reference to `boost::log_mt_posix::basic_core<char>::get()' /usr/include/boost/log/sources/basic_logger.hpp:145: undefined reference to `boost::log_mt_posix::basic_attribute_set<char>::basic_attribute_set()' ./main.o: In function `~pair': /usr/include/c++/4.5/bits/stl_pair.h:72: undefined reference to `boost::log_mt_posix::basic_slim_string<char, std::char_traits<char> >::~basic_slim_string()' /usr/include/c++/4.5/bits/stl_pair.h:72: undefined reference to `boost::log_mt_posix::basic_slim_string<char, std::char_traits<char> >::~basic_slim_string()' ./main.o: In function `basic_logger': /usr/include/boost/log/sources/basic_logger.hpp:135: undefined reference to `boost::log_mt_posix::basic_core<char>::get()' /usr/include/boost/log/sources/basic_logger.hpp:135: undefined reference to `boost::log_mt_posix::basic_attribute_set<char>::basic_attribute_set(boost::log_mt_posix::basic_attribute_set<char> const&)' ./main.o: In function `boost::log_mt_posix::basic_attribute_set<char>::reference_proxy::operator=(boost::shared_ptr<boost::log_mt_posix::attribute> const&) const': /usr/include/boost/log/attributes/attribute_set.hpp:121: undefined reference to `boost::log_mt_posix::basic_slim_string<char, std::char_traits<char> >::basic_slim_string(char const*, unsigned long)' /usr/include/boost/log/attributes/attribute_set.hpp:121: undefined reference to `boost::log_mt_posix::basic_attribute_set<char>::insert(boost::log_mt_posix::basic_slim_string<char, std::char_traits<char> > const&, boost::shared_ptr<boost::log_mt_posix::attribute> const&)' /usr/include/boost/log/attributes/attribute_set.hpp:121: undefined reference to `boost::log_mt_posix::basic_slim_string<char, std::char_traits<char> >::~basic_slim_string()' /usr/include/boost/log/attributes/attribute_set.hpp:121: undefined reference to `boost::log_mt_posix::basic_slim_string<char, std::char_traits<char> >::~basic_slim_string()' ./main.o: In function `pair<std::basic_string<char>, boost::shared_ptr<boost::log_mt_posix::attribute> >': /usr/include/c++/4.5/bits/stl_pair.h:116: undefined reference to `boost::log_mt_posix::basic_slim_string<char, std::char_traits<char> >::basic_slim_string(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' ./main.o: In function `boost::log_mt_posix::basic_attribute_set<char>::insert(std::pair<boost::log_mt_posix::basic_slim_string<char, std::char_traits<char> > const, boost::shared_ptr<boost::log_mt_posix::attribute> > const&)': /usr/include/boost/log/attributes/attribute_set.hpp:507: undefined reference to `boost::log_mt_posix::basic_attribute_set<char>::insert(boost::log_mt_posix::basic_slim_string<char, std::char_traits<char> > const&, boost::shared_ptr<boost::log_mt_posix::attribute> const&)' ./main.o: In function `boost::log_mt_posix::sources::aux::severity_level<boost::log_mt_posix::trivial::severity_level>::dispatch(boost::log_mt_posix::type_dispatcher&)': /usr/include/boost/log/sources/severity_feature.hpp:105: undefined reference to `boost::log_mt_posix::sources::aux::get_severity_level()' ./main.o: In function `boost::log_mt_posix::sources::aux::severity_level<boost::log_mt_posix::trivial::severity_level>::detach_from_thread()': /usr/include/boost/log/sources/severity_feature.hpp:118: undefined reference to `boost::log_mt_posix::sources::aux::get_severity_level()' collect2: ld returned 1 exit status make: *** [LoggingCpp] Error 1 

Boost syntax syntax

Failed to install Boost Log incorrectly? Did I miss important libraries? Did I miss the necessary linker flags?

+7
source share
3 answers

It looks like you did not create a magazine?

Once you have copied the log header files, etc. into the appropriate folders in your boost distribution (keep the same structure, that is, combine the headers into headers, the libs folder into the libs folder of your boost distribution, etc.), you still need to increase the momentum, and then, as mentioned above, refers on him. Therefore, the link you mentioned above points to standard formatting instructions.

Not so long ago, but AFAIR on linux you just run ./bjam in the root of your boost folder.

0
source

You need to add something like -lboost-log-mt to your link line.

+1
source

Maybe you can disable the unfast version of boost_log.

I have the same problem for undefined link to "boost :: log :: v2_mt_posix :: core :: push_record_move (boost :: log :: v2_mt_posix :: record &)"

I create libboost_log myself. And I use nm for grep that push_record_move found that "boost :: log :: v2s_mt_posix :: core :: push_record_move (boost :: log :: v2s_mt_posix :: record &)"

From the experience of the previous, you should add some cflag to the Makefile.

0
source

All Articles