我正在学习Boost,并且在制作文件时遇到问题。 这里是我的基本的makefile:在make文件中包含boost库
accesstimer: acctime.o btimer.o
g++ acctime.o btimer.o -o accesstimer
acctime.o: acctime.cpp btimer.h
g++ -c acctime.cpp
bentimer.o: btimer.cpp btimer.h
g++ -c btimer.cpp
当acctime.cpp没有提高文件系统元素,它这个男,AKE文件工作正常。 只要我添加boost文件系统元素,我显然需要引用make文件中的boost libray,这是我遇到问题的地方。
下面一行适用于单个文件编译:
g++ -I /usr/local/boost/boost_1_39_0 boosttest1.cpp -o bt1 /usr/local/boost/boost_1_39_0/stage/lib/libboost_filesystem-gcc41-mt.a /usr/local/boost/boost_1_39_0/stage/lib/libboost_system-gcc41-mt.a
现在,我想这个融入make文件。我试过很多基于什么样的信息,我可以在网上找到,但没有正在这是我最新的:
accesstimer: acctime.o bentimer.o
g++ acctime.o bentimer.o -o accesstimer
acctime.o: acctime.cpp bentimer.h
g++ -c -I /usr/local/boost/boost_1_39_0 acctime.cpp /usr/local/boost/boost_1_39_0/stage/lib/libboost_filesystem-gcc41-mt.a /usr/local/boost/boost_1_39_0/stage/lib/libboost_system-gcc41-mt.a
bentimer.o: bentimer.cpp bentimer.h
g++ -c bentimer.cpp
不幸的是,stlill找不到Boost库,任何人都可以帮忙吗? 感谢
看了谁已经回答了人们现在我有了这个的建议:
accesstimer: acctime.o bentimer.o
g++ -L /usr/local/boost/boost_1_39_0 acctime.o /usr/local/boost/boost_1_39_0/stage/lib/libboost_filesystem-gcc41-mt.a /usr/local/boost/boost_1_39_0/stage/lib/libboost_system-gcc41-mt.a bentimer.o -o accesstimer
acctime.o: acctime.cpp bentimer.h
g++ -c acctime.cpp
bentimer.o: bentimer.cpp bentimer.h
g++ -c bentimer.cpp
但是,这仍然无法链接。
这是错误消息我得到:(!感谢大加赞赏)
g++ -L /usr/local/boost/boost_1_39_0/stage/lib/libboost_filesystem-gcc41-mt.a /usr/local/boost/boost_1_39_0/stage/lib/libboost_system-gcc41-mt.a 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&)]+0x26): undefined reference to `boost::filesystem::detail::status_api(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int&)'
collect2: ld returned 1 exit status
make: *** [accesstimer] Error 1
继orsogufo的意见,现在有这样的:
accesstimer: acctime.o bentimer.o
g++ -L/usr/local/boost/boost_1_39_0/stage/lib -llibboost_filesystem-gcc41-mt.a -llibboost_system-gcc41-mt.a acctime.o bentimer.o -o accesstimer
acctime.o: acctime.cpp bentimer.h
g++ -c acctime.cpp
bentimer.o: bentimer.cpp bentimer.h
g++ -c bentimer.cpp
迎向美好的,但还是不太找到库:
g++ -L/usr/local/boost/boost_1_39_0/stage/lib -llibboost_filesystem-gcc41-mt.a -llibboost_system-gcc41-mt.a acctime.o bentimer.o -o accesstimer
/usr/bin/ld: cannot find -llibboost_filesystem-gcc41-mt.a
collect2: ld returned 1 exit status
make: *** [accesstimer] Error 1
我仔细检查过该位置和库是肯定的: /usr/local/boost/boost_1_39_0/stage/lib/libboost_filesystem-gcc41-mt.a
仍然没有喜悦,现在usimg这样的:
accesstimer: acctime.o bentimer.o
g++ -L/usr/local/boost/boost_1_39_0 -lboost_filesystem-gcc41-mt 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
获取:
g++ -L/usr/local/boost/boost_1_39_0/stage/lib/ -llibboost_filesystem-gcc41-mt acctime.o bentimer.o -o accesstimer
/usr/bin/ld: cannot find -llibboost_filesystem-gcc41-mt
collect2: ld returned 1 exit status
make: *** [accesstimer] Error 1
这是这个工作:
accesstimer: acctime.o bentimer.o
g++ -L/usr/local/boost/boost_1_39_0/stage/lib -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
感谢您的帮助
能否请您发表您收到错误消息? – 2009-08-20 12:16:27
当你使用-l标志链接库时,你总是离开前面的“lib”。因此,链接libm.a是-lm,libboost是-lboost等。 – 2009-08-20 13:35:35