Project

General

Profile

Actions

Bug #3982

closed

Linker error when using NDN_LOG_*

Added by Junxiao Shi almost 8 years ago. Updated almost 6 years ago.

Status:
Closed
Priority:
Normal
Category:
Utils
Target version:
Start date:
Due date:
% Done:

100%

Estimated time:
1.00 h

Description

Snippet to reproduce:

#include <ndn-cxx/util/logger.hpp>

NDN_LOG_INIT(MyLogModule);

int
main()
{
  NDN_LOG_FATAL("my-fatal");
}

Expected: code compiles with g++ -o x -std=c++14 x.cpp $(pkg-config --cflags --libs libndn-cxx)
Actual:

/tmp/ccZHMwXm.o: In function `boost::log::v2s_mt_posix::record::reset()':
x.cpp:(.text._ZN5boost3log12v2s_mt_posix6record5resetEv[_ZN5boost3log12v2s_mt_posix6record5resetEv]+0x23): undefined reference to `boost::log::v2s_mt_posix::record_view::public_data::destroy(boost::log::v2s_mt_posix::record_view::public_data const*)'
/tmp/ccZHMwXm.o: In function `boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::logger_mt, boost::log::v2s_mt_posix::sources::multi_thread_model<boost::log::v2s_mt_posix::aux::light_rw_mutex> >::~basic_logger()':
x.cpp:(.text._ZN5boost3log12v2s_mt_posix7sources12basic_loggerIcNS2_9logger_mtENS2_18multi_thread_modelINS1_3aux14light_rw_mutexEEEED2Ev[_ZN5boost3log12v2s_mt_posix7sources12basic_loggerIcNS2_9logger_mtENS2_18multi_thread_modelINS1_3aux14light_rw_mutexEEEED5Ev]+0x18): undefined reference to `boost::log::v2s_mt_posix::attribute_set::~attribute_set()'
/tmp/ccZHMwXm.o: In function `boost::log::v2s_mt_posix::sources::basic_composite_logger<char, boost::log::v2s_mt_posix::sources::logger_mt, boost::log::v2s_mt_posix::sources::multi_thread_model<boost::log::v2s_mt_posix::aux::light_rw_mutex>, boost::log::v2s_mt_posix::sources::features<> >::open_record()':
x.cpp:(.text._ZN5boost3log12v2s_mt_posix7sources22basic_composite_loggerIcNS2_9logger_mtENS2_18multi_thread_modelINS1_3aux14light_rw_mutexEEENS2_8featuresIIEEEE11open_recordEv[_ZN5boost3log12v2s_mt_posix7sources22basic_composite_loggerIcNS2_9logger_mtENS2_18multi_thread_modelINS1_3aux14light_rw_mutexEEENS2_8featuresIIEEEE11open_recordEv]+0x29): undefined reference to `boost::log::v2s_mt_posix::core::get_logging_enabled() const'
/tmp/ccZHMwXm.o: In function `boost::log::v2s_mt_posix::aux::record_pump<ndn::util::Logger>::~record_pump()':
x.cpp:(.text._ZN5boost3log12v2s_mt_posix3aux11record_pumpIN3ndn4util6LoggerEED2Ev[_ZN5boost3log12v2s_mt_posix3aux11record_pumpIN3ndn4util6LoggerEED5Ev]+0x3c): undefined reference to `boost::log::v2s_mt_posix::aux::unhandled_exception_count()'
/tmp/ccZHMwXm.o: In function `boost::log::v2s_mt_posix::record boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::logger_mt, boost::log::v2s_mt_posix::sources::multi_thread_model<boost::log::v2s_mt_posix::aux::light_rw_mutex> >::open_record_unlocked<boost::parameter::aux::empty_arg_list>(boost::parameter::aux::empty_arg_list const&)':
x.cpp:(.text._ZN5boost3log12v2s_mt_posix7sources12basic_loggerIcNS2_9logger_mtENS2_18multi_thread_modelINS1_3aux14light_rw_mutexEEEE20open_record_unlockedINS_9parameter3aux14empty_arg_listEEENS1_6recordERKT_[_ZN5boost3log12v2s_mt_posix7sources12basic_loggerIcNS2_9logger_mtENS2_18multi_thread_modelINS1_3aux14light_rw_mutexEEEE20open_record_unlockedINS_9parameter3aux14empty_arg_listEEENS1_6recordERKT_]+0x3e): undefined reference to `boost::log::v2s_mt_posix::core::open_record(boost::log::v2s_mt_posix::attribute_set const&)'
/tmp/ccZHMwXm.o: In function `boost::log::v2s_mt_posix::aux::record_pump<ndn::util::Logger>::record_pump(ndn::util::Logger&, boost::log::v2s_mt_posix::record&)':
x.cpp:(.text._ZN5boost3log12v2s_mt_posix3aux11record_pumpIN3ndn4util6LoggerEEC2ERS6_RNS1_6recordE[_ZN5boost3log12v2s_mt_posix3aux11record_pumpIN3ndn4util6LoggerEEC5ERS6_RNS1_6recordE]+0x2f): undefined reference to `boost::log::v2s_mt_posix::aux::stream_provider<char>::allocate_compound(boost::log::v2s_mt_posix::record&)'
x.cpp:(.text._ZN5boost3log12v2s_mt_posix3aux11record_pumpIN3ndn4util6LoggerEEC2ERS6_RNS1_6recordE[_ZN5boost3log12v2s_mt_posix3aux11record_pumpIN3ndn4util6LoggerEEC5ERS6_RNS1_6recordE]+0x3c): undefined reference to `boost::log::v2s_mt_posix::aux::unhandled_exception_count()'
/tmp/ccZHMwXm.o: In function `boost::log::v2s_mt_posix::aux::record_pump<ndn::util::Logger>::auto_release::~auto_release()':
x.cpp:(.text._ZN5boost3log12v2s_mt_posix3aux11record_pumpIN3ndn4util6LoggerEE12auto_releaseD2Ev[_ZN5boost3log12v2s_mt_posix3aux11record_pumpIN3ndn4util6LoggerEE12auto_releaseD5Ev]+0x17): undefined reference to `boost::log::v2s_mt_posix::aux::stream_provider<char>::release_compound(boost::log::v2s_mt_posix::aux::stream_provider<char>::stream_compound*)'
/tmp/ccZHMwXm.o: In function `boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::logger_mt, boost::log::v2s_mt_posix::sources::multi_thread_model<boost::log::v2s_mt_posix::aux::light_rw_mutex> >::push_record_unlocked(boost::log::v2s_mt_posix::record&&)':
x.cpp:(.text._ZN5boost3log12v2s_mt_posix7sources12basic_loggerIcNS2_9logger_mtENS2_18multi_thread_modelINS1_3aux14light_rw_mutexEEEE20push_record_unlockedEONS1_6recordE[_ZN5boost3log12v2s_mt_posix7sources12basic_loggerIcNS2_9logger_mtENS2_18multi_thread_modelINS1_3aux14light_rw_mutexEEEE20push_record_unlockedEONS1_6recordE]+0x47): undefined reference to `boost::log::v2s_mt_posix::core::push_record_move(boost::log::v2s_mt_posix::record&)'
collect2: error: ld returned 1 exit status

g++ -o x -std=c++11 x.cpp $(pkg-config --cflags --libs libndn-cxx) -DBOOST_LOG_DYN_LINK works fine.
-DBOOST_LOG_DYN_LINK argument should be added into pkg-config output.

Actions #1

Updated by Davide Pesavento almost 8 years ago

We did have -DBOOST_LOG_DYN_LINK in the .pc file in the hackathon project, but during the code review to integrate that code in the official ndn-cxx, Alex was against adding the define and it was removed. He said he preferred to add it to ndn-cxx-config.hpp, but didn't explain why. I believe the .pc file is the correct place for this.

Actions #2

Updated by Junxiao Shi almost 8 years ago

add it to ndn-cxx-config.hpp

Adding -DBOOST_LOG_DYN_LINK to ndn-cxx-config.hpp is as good as adding it to .pc. Either way can fix this bug.

Actions #3

Updated by Davide Pesavento almost 8 years ago

Junxiao Shi wrote:

Adding -DBOOST_LOG_DYN_LINK to ndn-cxx-config.hpp is a good as adding it to .pc. Either way can fix this bug.

No, it's not the same thing. If the define is in ndn-cxx-config.hpp, third-party code needs to ensure that ndn-cxx-config.hpp is (indirectly) included before any Boost.Log headers. The .pc file doesn't have this shortcoming.

Actions #4

Updated by Junxiao Shi almost 8 years ago

third-party code needs to ensure that ndn-cxx-config.hpp is (indirectly) included before any Boost.Log headers

Third party code is not supposed to both directly use Boost.Log and use ndn-cxx logging. See #3782.

Actions #5

Updated by Alex Afanasyev almost 8 years ago

Davide Pesavento wrote:

Junxiao Shi wrote:

Adding -DBOOST_LOG_DYN_LINK to ndn-cxx-config.hpp is a good as adding it to .pc. Either way can fix this bug.

No, it's not the same thing. If the define is in ndn-cxx-config.hpp, third-party code needs to ensure that ndn-cxx-config.hpp is (indirectly) included before any Boost.Log headers. The .pc file doesn't have this shortcoming.

I still don't agree with putting it in .pc file. The reason for the error is because code explicitly requires ndn-cxx log routines to be used. Which implies that all necessary elements should have been included (ndn-cxx-common.hpp) as part of that. Putting define in .pc precludes app from using Boost.Log in whatever other way the app wants to use Boost.Log.

Actions #6

Updated by Davide Pesavento almost 8 years ago

Alex Afanasyev wrote:

Putting define in .pc precludes app from using Boost.Log in whatever other way the app wants to use Boost.Log.

What does that mean? Why does the define preclude that?

-DBOOST_LOG_DYN_LINK simply means "use dynamic linking", it doesn't change how the application uses the Boost.Log library.

Actions #7

Updated by Junxiao Shi over 7 years ago

third-party code needs to ensure that ndn-cxx-config.hpp is (indirectly) included before any Boost.Log headers

... and that is a violation of rule 3.4 which requires "low level" Boost includes to appear before any ndn-cxx includes. Thus, pkg-config is the only way.

Actions #8

Updated by Davide Pesavento over 6 years ago

  • Target version changed from v0.6 to v0.7
  • Start date deleted (02/28/2017)
Actions #9

Updated by Alex Afanasyev almost 6 years ago

  • Description updated (diff)
Actions #10

Updated by Alex Afanasyev almost 6 years ago

  • Assignee set to Alex Afanasyev
  • % Done changed from 0 to 100
Actions #11

Updated by Alex Afanasyev almost 6 years ago

  • Status changed from New to Code review
Actions #12

Updated by Davide Pesavento almost 6 years ago

  • Status changed from Code review to Closed
Actions

Also available in: Atom PDF