0

I'm working on a source code migration from VS'2008+Boost 1.144 to VS'2015+Boost 1.61 and I got the following link error

... error LNK2019: unresolved external symbol "__declspec(dllimport) public: static void __cdecl boost::log::v2_mt_nt5::attributes::named_scope::push_scope(struct boost::log::v2_mt_nt5::attributes::named_scope_entry const &)" (__imp_?push_scope@named_scope@attributes@v2_mt_nt5@log@boost@@SAXABUnamed_scope_entry@2345@@Z) referenced in function "public: __thiscall boost::log::v2_mt_nt5::attributes::named_scope::sentry::sentry(class boost::log::v2_mt_nt5::basic_string_literal<char,struct std::char_traits<char> > const &,class boost::log::v2_mt_nt5::basic_string_literal<char,struct std::char_traits<char> > const &,unsigned int,enum boost::log::v2_mt_nt5::attributes::named_scope_entry::scope_name_type)" (??0sentry@named_scope@attributes@v2_mt_nt5@log@boost@@QAE@ABV?$basic_string_literal@DU?$char_traits@D@std@@@345@0IW4scope_name_type@named_scope_entry@2345@@Z)
... : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static void __cdecl boost::log::v2_mt_nt5::attributes::named_scope::pop_scope(void)" (__imp_?pop_scope@named_scope@attributes@v2_mt_nt5@log@boost@@SAXXZ) referenced in function "public: __thiscall boost::log::v2_mt_nt5::attributes::named_scope::sentry::~sentry(void)" (??1sentry@named_scope@attributes@v2_mt_nt5@log@boost@@QAE@XZ)

To build boost I used :

bootstrap.bat
b2 --build-dir=build-directory toolset=msvc-14.0 --build-type=complete define=BOOST_LOG_NO_COMPILER_TLS stage

And in source code I used BOOST_LOG_DYN_LINK. It seems that all the other boost lib I'm using are found and linked correctly but not boost log and only those 2 functions.

I noticed that in boost/log/attributes/named_scoped.hpp those 2 functions are defined as static memberof the named_scopeclass (see below). And I'm wondering if it could be the reason of that linkage issue ? Because I'm not sure that a static function can be exported/loaded from a dll !

 /*!
     * The method pushes the scope to the back of the current thread's scope list
     *
     * \b Throws: Nothing.
     */
    static void push_scope(scope_entry const& entry) BOOST_NOEXCEPT;
    /*!
     * The method pops the last pushed scope from the current thread's scope list
     *
     * \b Throws: Nothing.
     */
    static void pop_scope() BOOST_NOEXCEPT;

Any idea or advice to fix that problem would be welcome.

alexbuisson
  • 7,699
  • 3
  • 31
  • 44
  • Can you double check the libraries that you're linking against in VS? I have found Boost's automatic linking to be tricky. Also, it looks like BOOST_LOG_USE_COMPILER_TLS may have replaced BOOST_LOG_NO_COMPILER_TLS, but it is unclear if this has any bearing on the problem. – Robert Prévost Aug 31 '16 at 02:54
  • `static` member functions are not the issue. – rustyx Aug 31 '16 at 15:20

1 Answers1

1

I suspect you have target Windows API version mismatch between your code and Boost.Log. See this answer.

Community
  • 1
  • 1
Andrey Semashev
  • 10,046
  • 1
  • 17
  • 27
  • If a question has the same answer as another question, it is very likely a duplicate. Duplicates should be flagged as such, using the link underneath the question's tags. "flag" -> "a duplicate" -> enter link. – Cody Gray - on strike Aug 31 '16 at 15:35