我已经下载了boost并构建了它,而不是第一次,但事情开始变得很奇怪了。
起初我在编译项目时遇到了这些错误(使用boost):
/usr/local/include/boost/system/error_code.hpp:221: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:223: undefined reference to `boost::system::system_category()'
/usr/local/include/boost/system/error_code.hpp:221: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:223: undefined reference to `boost::system::system_category()'
/usr/local/include/boost/thread/exceptions.hpp:51: undefined reference to `boost::system::system_category()'
/usr/local/include/boost/thread/exceptions.hpp:84: undefined reference to `boost::system::system_category()'
/usr/local/include/boost/thread/pthread/thread_data.hpp:152: undefined reference to `vtable for boost::detail::thread_data_base'
/usr/local/include/boost/thread/pthread/thread_data.hpp:195: undefined reference to `boost::detail::get_current_thread_data()'
/usr/local/include/boost/thread/detail/thread.hpp:179: undefined reference to `boost::thread::start_thread_noexcept()'
/usr/local/include/boost/thread/detail/thread.hpp:741: undefined reference to `boost::thread::native_handle()'
/usr/local/include/boost/thread/detail/thread.hpp:767: undefined reference to `boost::thread::join_noexcept()'
/usr/local/include/boost/thread/detail/thread.hpp:779: undefined reference to `boost::thread::do_try_join_until_noexcept(timespec const&, bool&)'
/usr/local/include/boost/thread/pthread/condition_variable.hpp:84: undefined reference to `boost::this_thread::interruption_point()'
/usr/local/include/boost/thread/detail/thread.hpp:90: undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
/usr/local/include/boost/system/error_code.hpp:221: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
/usr/local/include/boost/system/error_code.hpp:223: undefined reference to `boost::system::system_category()'
所以我去检查一切是否到位,发现我没有通常的库命名的升级lib文件,就是它们看起来像:libboost_thread.a
,libboost_system.a
,libboost_date_time.a
,而不是-mt
,-d
等等上。
我不记得我是如何构建的,但如果我尝试运行:
boost_src_dir > ./b2 threading=multi link=static variant=debug,release
我明白了:
error: Name clash for '<pstage/lib>libboost_atomic.a'
error:
error: Tried to build the target twice, with property sets having
error: these incompatible properties:
error:
error: - <debug-symbols>on <inlining>off <optimization>off <runtime-debugging>on <variant>debug
error: - <debug-symbols>off <define>NDEBUG <inlining>full <optimization>speed <runtime-debugging>off <variant>release
error:
error: Please make sure to have consistent requirements for these
error: properties everywhere in your project, especially for install
error: targets.
不太清楚发生了什么事,以前我做过这件事它很顺利.. 有任何想法吗?
我正在使用linux mint(17.2 x64),提升1.59并将其与cmake一起使用,如下所示:
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost 1.36.0 COMPONENTS system thread shared_ptr)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})
else()
message("can not find boost")
endif()
谢谢。
在你的提升仓库中,如果你想要它在非默认位置,请确保你使用./bootstrap.sh
运行--prefix=<install directory>
。你不需要这个论点。
您可以在此之后从同一目录运行./b2命令,如果需要,可以使用--prefix=<install directory>
选项再次安装boost。在尝试执行此操作之前,您可能必须从构建/安装目录中删除所有以前的构建文件。
此外,请确保您的计算机具有正确的版本。我用http://downloads.sourceforge.net/boost/boost_1_58_0.tar.bz2作为我的(OpenSUSE 13.1 64位)
关于报告的error: Name clash for '<pstage/lib>libboost_atomic.a'
:
我只是在这里总结一下解释和解决方案(@Nitzan Tomer给briefly above,为此,@ Samidamaru的答案没有提供解决方案)。
问题是关于--layout
规范。有关b2 --help
选项,请参阅--layout
。
在Linux上,默认布局是system
,这意味着对于所有类型的构建,库都是使用模式创建的:libboost_<library-name>.a
(或Windows上的.lib
)。这意味着将为debug
和release
变体创建相同的文件。由于Nitzan通过传递variant=debug,release
来请求两个变体,因此创建的文件会相互覆盖。 b2
报告这是一个错误。
+-----------------------+-------------------------------------------------------------------------------+----------------------------------------+-------------------------+ | | --layout | +-----------------------+-------------------------------------------------------------------------------+----------------------------------------+-------------------------+ | | versioned | tagged | system | +-----------------------+-------------------------------------------------------------------------------+----------------------------------------+-------------------------+ | Library file name: | libboost_{lib name}-{toolset}[-mt]-{ABI tag}-{ARCH tag}-{boost ver tag}.lib | libboost_{lib name}[-mt]-{ABI tag}.lib | libboost_{lib name}.lib | +-----------------------+-------------------------------------------------------------------------------+----------------------------------------+-------------------------+ | Header file directory:| include/boost_{boost ver tag} | include | include | +-----------------------+-------------------------------------------------------------------------------+----------------------------------------+-------------------------+ | Notes: | Default on Windows. | Different toolsets (eg. different | Default on Linux. | | | All variations can be created in the same folder. | compiler versions), architecture and | All variations must be | | | See "Library naming" at | address-model CANNOT be generated in | created in separate | | | https://www.boost.org/doc/libs/1_68_0/more/getting_started/unix-variants.html | the same folder. But relase/debug and | folders. | | | The corresponding b2 options are also indicated on this page. | single/multi-threaded can be. | | +-----------------------+-------------------------------------------------------------------------------+----------------------------------------+-------------------------+
当然在Linux上使用.a
和.so
后修复版与Windows上的.lib
和.dll
。 Windows上的DLL名称中省略了lib
前缀。在Windows上,只有在设置了runtime-link=static
选项时才能创建单线程版本。
对于标题,仍然在指定的文件夹下创建“通常的”boost
目录。
这意味着,如果你通过例如--prefix=/tools/boost
到b2
,然后为versioned
布局创建以下目录结构:
/tools/boost | +--- lib | +--- include +--- boost_{boost version tag} | +--- boost +--- accumulators +--- algorithm etc.
不为其他布局创建boost_{boost version tag}
(例如boost_1_68
)中间目录。