linux boost filesystem程序链接,在Linux中链接Boost库

我正在尝试使用Boost的Asio构建一个项目,我遇到了一些麻烦。最初,我试图在没有任何额外库的情况下构建项目,因为所有内容都应该在头文件中。

我正在尝试构建的程序如下所示:

#include

#include

#include

int main()

{

boost::asio::io_service io;

boost::asio::deadline_timer t(io, boost::posix_time::seconds(5));

t.wait();

std::cout << "Hello, world!" << std::endl;

return 0;

}可以在Boost的网站上找到here。

所以,最初我只是:

-I /usr/include/boost_1_40_0这导致以下错误:

make -k all

Building target: HelloWorld

Invoking: GCC C++ Linker

g++ -o"HelloWorld" ./main.o

./main.o: In function `__static_initialization_and_destruction_0':

/usr/include/boost_1_40_0/boost/system/error_code.hpp:205: undefined reference to `boost::system::get_system_category()'

/usr/include/boost_1_40_0/boost/system/error_code.hpp:206: undefined reference to `boost::system::get_generic_category()'

/usr/include/boost_1_40_0/boost/system/error_code.hpp:211: undefined reference to `boost::system::get_generic_category()'

/usr/include/boost_1_40_0/boost/system/error_code.hpp:212: undefined reference to `boost::system::get_generic_category()'

/usr/include/boost_1_40_0/boost/system/error_code.hpp:213: undefined reference to `boost::system::get_system_category()'

./main.o: In function `boost::asio::error::get_system_category()':

/usr/include/boost_1_40_0/boost/asio/error.hpp:218: undefined reference to `boost::system::get_system_category()'

./main.o: In function `error_code':

/usr/include/boost_1_40_0/boost/system/error_code.hpp:312: undefined reference to `boost::system::get_system_category()'

./main.o: In function `posix_tss_ptr':

/usr/include/boost_1_40_0/boost/asio/detail/posix_tss_ptr.hpp:47: undefined reference to `pthread_key_create'

./main.o: In function `~posix_tss_ptr':

/usr/include/boost_1_40_0/boost/asio/detail/posix_tss_ptr.hpp:61: undefined reference to `pthread_key_delete'

./main.o: In function `boost::asio::detail::posix_thread::join()':

/usr/include/boost_1_40_0/boost/asio/detail/posix_thread.hpp:77: undefined reference to `pthread_join'

./main.o: In function `~posix_thread':

/usr/include/boost_1_40_0/boost/asio/detail/posix_thread.hpp:69: undefined reference to `pthread_detach'

collect2: ld returned 1 exit status

make: *** [HelloWorld] Error 1

make: Target `all' not remade because of errors.看来我需要系统库。所以,我按照入门指南中的说明找到了here,它给了我一些位于/ usr/include/boost_1_40_0/stage/lib中的库。其中有libboost_system.a。因此,我尝试编译:

-I /usr/include/boost_1_40_0

-L /usr/include/boost_1_40_0/stage/lib

-l libboost_system但是,我得到了这个:

make -k all

Building target: HelloWorld

Invoking: GCC C++ Linker

g++ -L/usr/lib -L/usr/include/boost_1_40_0/stage/lib -o"HelloWorld" ./main.o -llibboost_system

/usr/bin/ld: cannot find -llibboost_system

collect2: ld returned 1 exit status

make: *** [HelloWorld] Error 1

make: Target `all' not remade because of errors.我不知道为什么,但它似乎无法识别我尝试的库或任何其他库。我可能做错了什么?提前致谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值