2009-08-20 61 views
4

刚刚问了一个关于在make文件中连接Boost库的问题。 感谢那些帮助过的人。我结束了这个:无法链接makefile中的boost.system

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 

你知道wjat我做错了吗?

现在我已经添加了-I升压根链接到第一链接命令它建立罚款:

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 

该文件存在,但它没有选择它。

回答

1

对我的回答,希望对大家有所帮助别人其他如下: 我有问题的链接,这里的好人让我把正确的东西放在我的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 

在我的Linux机器,我对刚刚安装升压并建造了filesytem库。 我在劝说,因为需要为我的系统运行ldconfig来获取我已经安装的新库。现在起作用了。

4

其实你不应该删除整个尾部部分,只有扩展:

-lboost_system-gcc41-mt 

这同样适用于boost_filesystem:

-lboost_filesystem-gcc41-mt 
+0

-lboost_filesystem对我来说工作得很好。 – 2010-09-23 12:18:04

+0

@Robert:这可能意味着你的库路径中安装了一个'libboost_filesystem.so'符号链接,但是大多数情况下,这个链接不在那里,因为你想确保你使用的是相同的编译器等,因此libname越长。 – UncleZeiv 2010-09-23 14:48:27

+0

够公平的......看起来你是对的。 Thankyou Ubuntu符号链接。 – 2010-09-23 22:24:07