【问题标题】:cannot link boost.system in makefile无法在 makefile 中链接 boost.system
【发布时间】:2010-11-21 08:53:13
【问题描述】:

刚刚问了一个关于在 make 文件中链接 Boost 库的问题。 感谢那些为此提供帮助的人。我最终得到了这个:

accesstimer: acctime.o bentimer.o
    g++ -L/usr/local/boost/boost_1_39_0/stage/lib -lboost_system -lboost_filesystem   acctime.o bentimer.o -o accesstimer   

acctime.o: acctime.cpp bentimer.h
    g++ -I /usr/local/boost/boost_1_39_0 -c acctime.cpp 

bentimer.o: bentimer.cpp bentimer.h
    g++ -c bentimer.cpp 

我现在的问题是 boost.filesystem 需要 boost.system 而上面的 make 文件找不到 boost.system。

我通过查看 stage/lib 目录并删除文件名的 lib 和尾随部分 (libboost_filesystem-gcc41-mt.a) 获得了 boost.filesystem 的名称。正如你在上面看到的,我对 libboost_system-gcc41-mt.a 做了同样的事情,并提出了 boost_system 但找不到它。

有人知道我将如何链接 boost.system 吗?

感谢 zeive 叔叔,这很有效,但是当我尝试使用文件系统关键字之一(例如存在)时,我得到了这个:

g++ -I /usr/local/boost/boost_1_39_0 -c acctime.cpp
In file included from acctime.cpp:5:
bentimer.h:2:19: warning: extra tokens at end of #ifndef directive
bentimer.h:11:18: warning: extra tokens at end of #ifdef directive
bentimer.h:28:3: warning: no newline at end of file
g++ -L/usr/local/boost/boost_1_39_0/stage/lib -lboost_system-gcc41-mt -lboost_filesystem   acctime.o bentimer.o -o accesstimer
acctime.o: In function `boost::enable_if<boost::filesystem::is_basic_path<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >, bool>::type boost::filesystem::exists<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >(boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> const&)':
acctime.cpp:(.text._ZN5boost10filesystem6existsINS0_10basic_pathISsNS0_11path_traitsEEEEENS_9enable_ifINS0_13is_basic_pathIT_EEbE4typeERKS7_[boost::enable_if<boost::filesystem::is_basic_path<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >, bool>::type boost::filesystem::exists<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >(boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> const&)]+0x35): undefined reference to `boost::filesystem::detail::status_api(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::system::error_code&)'
collect2: ld returned 1 exit status
make: *** [accesstimer] Error 1

你知道我在这里做错了吗?

现在我已将 -I boost root 链接添加到它构建的第一个链接命令中:

accesstimer: acctime.o bentimer.o
    g++ -L/usr/local/boost/boost_1_39_0/stage/lib -lboost_system-gcc41-mt -lboost_filesystem-gcc41-mt  -I /usr/local/boost/boost_1_39_0 acctime.o bentimer.o -o accesstimer     

acctime.o: acctime.cpp bentimer.h
    g++ -I /usr/local/boost/boost_1_39_0 -c acctime.cpp 

bentimer.o: bentimer.cpp bentimer.h
    g++ -c bentimer.cpp 

但是当我执行时我得到:

./accesstimer: error while loading shared libraries: libboost_system-gcc41-mt-1_39.so.1.39.0: cannot open shared object file: No such file or directory

该文件存在,但它没有拾取它。

【问题讨论】:

    标签: boost makefile linker


    【解决方案1】:

    实际上你不应该删除整个尾随部分,只删除扩展名:

    -lboost_system-gcc41-mt
    

    对于 boost_filesystem 也是如此:

    -lboost_filesystem-gcc41-mt
    

    【讨论】:

    • @Robert:这可能意味着您在库路径中安装了libboost_filesystem.so 符号链接,但大多数时候该链接不存在,因为您想确保使用相同的编译器等,因此 libname 更长。
    • 很公平……看来你是对的。谢谢 Ubuntu 符号链接。
    【解决方案2】:

    对我来说,希望对其他人有所帮助的答案如下: 我在链接时遇到问题,这里的好人让我把正确的东西放在我的 make 文件中,但我仍然得到:

    ./accesstimer: error while loading shared libraries: libboost_system-gcc41-mt-1_39.so.1.39.0: cannot open shared object file: No such file or directory
    

    解决方案是执行:

    ldconfig
    

    在我刚刚安装 Boost 并构建文件系统库的 Linux 机器上。 我保证,因为我的系统需要运行 ldconfig 才能获取我安装的新库。现在可以了。

    【讨论】:

      猜你喜欢
      • 2010-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-29
      • 2012-09-12
      • 1970-01-01
      • 1970-01-01
      • 2012-03-17
      相关资源
      最近更新 更多