gpt4 book ai didi

c++ - 使用 Boost.build 构建并链接到 boost

转载 作者:太空狗 更新时间:2023-10-29 21:48:22 26 4
gpt4 key购买 nike

当我开始一个带有 boost lib 的项目时,我的设置似乎不起作用:

main.cpp :

#include <boost/asio.hpp>
int main(int argc, char* argv[])
{
boost::asio::io_service io_service_;
return 0;
}

Jam 文件:

exe node
: main.cpp ;

bjam 将产生:

...found 30 targets...
...updating 2 targets...
gcc.compile.c++ bin/gcc-4.7.0/debug/main.o
gcc.link bin/gcc-4.7.0/debug/node
bin/gcc-4.7.0/debug/main.o: In function `__static_initialization_and_destruction_0':
/usr/include/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'
/usr/include/boost/system/error_code.hpp:215: undefined reference to `boost::system::generic_category()'
/usr/include/boost/system/error_code.hpp:216: undefined reference to `boost::system::system_category()'
bin/gcc-4.7.0/debug/main.o: In function `boost::system::error_code::error_code()':
/usr/include/boost/system/error_code.hpp:315: undefined reference to `boost::system::system_category()'
bin/gcc-4.7.0/debug/main.o: In function `boost::asio::error::get_system_category()':
/usr/include/boost/asio/error.hpp:216: undefined reference to `boost::system::system_category()'
bin/gcc-4.7.0/debug/main.o: In function `boost::asio::detail::posix_tss_ptr_create(unsigned int&)':
/usr/include/boost/asio/detail/impl/posix_tss_ptr.ipp:34: undefined reference to `pthread_key_create'
bin/gcc-4.7.0/debug/main.o: In function `boost::asio::detail::posix_tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::task_io_service, boost::asio::detail::task_io_service::thread_info>::context>::~posix_tss_ptr()':
/usr/include/boost/asio/detail/posix_tss_ptr.hpp:48: undefined reference to `pthread_key_delete'
bin/gcc-4.7.0/debug/main.o: In function `boost::asio::detail::posix_tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::strand_service::strand_impl, unsigned char>::context>::~posix_tss_ptr()':
/usr/include/boost/asio/detail/posix_tss_ptr.hpp:48: undefined reference to `pthread_key_delete'
collect2: error: ld returned 1 exit status

"g++" -o "bin/gcc-4.7.0/debug/node" -Wl,--start-group "bin/gcc-4.7.0/debug/main.o" -Wl,-Bstatic -Wl,-Bdynamic -Wl,--end-group -g


...failed gcc.link bin/gcc-4.7.0/debug/node...
...failed updating 1 target...
...updated 1 target...

bjam 似乎正确找到了 header ,但没有找到库。所以我试着告诉 bjam 在哪里可以找到 boost :

Jam 文件:

use-project /boost : /usr/lib/boost ;

exe node
: main.cpp
/boost//system
;

但是 bjam 现在会产生:

/usr/share/boost-build/build/project.jam:270: in find-jamfile from module project
error: Unable to load Jamfile.
error: Could not find a Jamfile in directory '/usr/lib/boost'.
error: Attempted to find it with pattern '[Bb]uild.jam [Jj]amfile.v2 [Jj]amfile [Jj]amfile.jam'.
error: Please consult the documentation at 'http://www.boost.org'.
/usr/share/boost-build/build/project.jam:290: in load-jamfile from module project
/usr/share/boost-build/build/project.jam:68: in project.load from module project
/usr/share/boost-build/build/project.jam:718: in project.use from module project
/usr/share/boost-build/build/project.jam:94: in load-used-projects from module project
/usr/share/boost-build/build/project.jam:79: in load from module project
/usr/share/boost-build/build/project.jam:170: in project.find from module project
/usr/share/boost-build/build-system.jam:248: in load from module build-system
/usr/share/boost-build/kernel/modules.jam:261: in import from module modules
/usr/share/boost-build/kernel/bootstrap.jam:132: in boost-build from module
/usr/share/boost-build/boost-build.jam:1: in module scope from module

不知道 bjam 想要重建 boost,这就是它在 /usr/lib/boost 中寻找 Jamfile 的原因。

有什么遗漏吗?我如何告诉 bjam 缺少链接的库在哪里?

前段时间,我用过

LINKLIBS = -lboost_system -lboost_filesystem ;

但我不知道如何为 Boost.build v2 翻译它。

谢谢。

最佳答案

最后,我得到了解决方案。我期待 <linkflags>能够获得多个库,但我错了。

这是解决方法,我将 Jamfile 更改为:

exe node
: main.cpp
: <linkflags>-lpthread
<linkflags>-lboost_system
;

关于c++ - 使用 Boost.build 构建并链接到 boost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10900313/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com