我正在學習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