-2

I have a problem I can't get rid off. I have a small private project where I want to use asio for network communication and boost threads. I don't wan`t install boost on my machine, so I integrated the sourcecode in my project. For that I created a global header including boost thread and asio, like this:

#include "boost/asio.hpp"
#include "boost/thread.hpp"

This way I can build static libs without problems, but shared libs or executables cause linker errors:

error LNK2019: unresolved external symbol "private: bool __cdecl boost::thread::join_noexcept(void)" (?join_noexcept@thread@boost@@AEAA_NXZ) referenced in function "public: void __cdecl boost::thread::join(void)" (?join@thread@boost@@QEAAXXZ)
error LNK2019: unresolved external symbol "class boost::thread::id __cdecl boost::this_thread::get_id(void)" (?get_id@this_thread@boost@@YA?AVid@thread@2@XZ) referenced in function "public: void __cdecl boost::thread::join(void)" (?join@thread@boost@@QEAAXXZ)
error LNK2019: unresolved external symbol "public: class boost::thread::id __cdecl boost::thread::get_id(void)const " (?get_id@thread@boost@@QEBA?AVid@12@XZ) referenced in function "public: void __cdecl boost::thread::join(void)" (?join@thread@boost@@QEAAXXZ)
error LNK2019: unresolved external symbol "private: bool __cdecl boost::thread::do_try_join_until_noexcept(unsigned __int64,bool &)" (?do_try_join_until_noexcept@thread@boost@@AEAA_N_KAEA_N@Z) referenced in function "private: bool __cdecl boost::thread::do_try_join_until(unsigned __int64)" (?do_try_join_until@thread@boost@@AEAA_N_K@Z)
error LNK2019: unresolved external symbol "public: void __cdecl boost::thread::interrupt(void)" (?interrupt@thread@boost@@QEAAXXZ) referenced in function "public: __cdecl NetworkAdapter::~NetworkAdapter(void)" (??1NetworkAdapter@@QEAA@XZ)
error LNK2019: unresolved external symbol "public: bool __cdecl boost::thread::joinable(void)const " (?joinable@thread@boost@@QEBA_NXZ) referenced in function "public: __cdecl NetworkAdapter::~NetworkAdapter(void)" (??1NetworkAdapter@@QEAA@XZ)

The current configuration for using boost as source within project so far is:

#define BOOST_SYSTEM_SOURCE
#define BOOST_DATE_TIME_NO_LIB
#define BOOST_REGEX_NO_LIB
#define BOOST_THREAD_DYN_LINK
#define BOOST_THREAD_DYN_DLL
#define BOOST_THREAD_BUILD_DLL
#define BOOST_CHRONO_HEADER_ONLY
#define BOOST_DATE_TIME_NO_LIB

Without this configuration linker asks for *.lib files for thread, chrono and so on. According to boost homepage Thread and Asio are HeaderOnly, so why is the linker looking for lib, missing symbols - instead of using headers? So what am I doing wrong?

Appreciating every hint :-)

Best regards, Dan

Tanner Sansbury
  • 51,153
  • 9
  • 112
  • 169
Dan
  • 1

1 Answers1

1

From the boost threading website

Boost.Thread depends on some non header-only libraries.

Boost.System: This dependency is mandatory and you will need to link with the library. Boost.Chrono: This dependency is optional (see below how to configure) and you will need to link with the library if you use some of the time related interfaces. Boost.DateTime: This dependency is mandatory, but even if Boost.DateTime is a non header-only library Boost.Thread uses only parts that are header-only, so in principle you should not need to link with the library.

So you're mistaken - it's not header only.

UKMonkey
  • 6,941
  • 3
  • 21
  • 30