Boost linker errors when using header-only libraries

感情迁移 提交于 2019-12-11 00:37:50

问题


I am using the following components of Boost 1.53.0 in conjunction with C++11 libraries...

  • boost::signals2::scoped_connection
  • boost::signals2::signal
  • boost::signals2::connection
  • boost::math::constants
  • boost::circular_buffer
  • boost::lexical_cast

According to this answer, I do not need to link against libraries to use these parts of Boost. According to this answer, signals2 should be header-only also. However, I still receive linker errors...

Undefined symbols for architecture i386:
  "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
  ...

Why?


回答1:


Boost.Signals2 is indeed header-only, but Boost.System is not. You have to make sure that you don't have any dependency on that library. If it's in your own code, you have to build Boost.System and link against it. If it's called from any header-only Boost library, file a bug report.




回答2:


The problem was a spurious

#include <boost/thread/mutex.hpp>

accidentally left in the middle of a file.



来源:https://stackoverflow.com/questions/16981448/boost-linker-errors-when-using-header-only-libraries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!