2009-08-20 62 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