2011-11-01 11 views
14

boost :: filesystemライブラリを利用するコードをコンパイルしようとすると、エラーが発生し続けます。私は私が得ているコンパイラの出力を理解していません。 C++ boost :: filesystem boost :: filesystem3 :: path :: root_name()constへの未定義の参照

#include <boost/filesystem.hpp> 
#include <iostream> 

int main(){ 
    boost::filesystem::path p("C:\\Windows\\System"); 
    std::cout << p.root_name() << std::endl; 
    std::cout << p.root_directory() << std::endl; 
    std::cout << p.root_path() << std::endl; 
    std::cout << p.relative_path() << std::endl; 
    std::cout << p.parent_path() << std::endl; 
    std::cout << p.filename() << std::endl; 
} 

は、私はUbuntuの11.10持っていると私はlibbost-devのとg ++をインストールしている:ここに私のコードは http://www.highscore.de/cpp/boost/dateisystem.html#dateisystem_pfadangabenからコピーされます。これは端末の外観です:

[email protected]:~/Dokumente/Programming/Projekte/FTP-abgleicher$ g++ -o pr3 pr3.cpp 
/tmp/ccrN7yHl.o: In function `main': 
pr3.cpp:(.text+0x3b): undefined reference to `boost::filesystem3::path::root_name() const' 
pr3.cpp:(.text+0x7e): undefined reference to `boost::filesystem3::path::root_directory() const' 
pr3.cpp:(.text+0xc1): undefined reference to `boost::filesystem3::path::root_path() const' 
pr3.cpp:(.text+0x104): undefined reference to `boost::filesystem3::path::relative_path() const' 
pr3.cpp:(.text+0x147): undefined reference to `boost::filesystem3::path::parent_path() const' 
pr3.cpp:(.text+0x18a): undefined reference to `boost::filesystem3::path::filename() const' 
pr3.cpp:(.text+0x1e8): undefined reference to `boost::filesystem3::path::stem() const' 
pr3.cpp:(.text+0x22b): undefined reference to `boost::filesystem3::path::extension() const' 

/tmp/ccrN7yHl.o: In function `__static_initialization_and_destruction_0(int, int)': 
pr3.cpp:(.text+0x364): undefined reference to `boost::system::generic_category()' 
pr3.cpp:(.text+0x36e): undefined reference to `boost::system::generic_category()' 
pr3.cpp:(.text+0x378): undefined reference to `boost::system::system_category()' 
/tmp/ccrN7yHl.o: In function `boost::filesystem3::path::codecvt()': 
pr3.cpp:(.text._ZN5boost11filesystem34path7codecvtEv[boost::filesystem3::path::codecvt()]+0x7): undefined reference to `boost::filesystem3::path::wchar_t_codecvt_facet()' 
collect2: ld gab 1 als Ende-Status zurück 

^Translation of last line: ld returned an end status of 1 

私は間違っていますか?

+1

次回は、コードをハイライト表示し、 'Ctrl + K 'を押すか、エディタで' {} 'ボタンを押してください。 – Mat

+0

[** 2012クリーンアップ**](http://meta.stackexchange.com/questions/128315/the-great-stack-overflow-tag-question-cleanup-of-2012)の一部として「german」タグが削除されました)。 –

答えて

27

-lboost_filesystem -lboost_systemとリンクする必要があります。 Boostファイルシステムはヘッダーのみのライブラリではありません。コンパイルされたコンポーネントに依存します。

+0

g ++ -lboost_filesystem -o pr3 pr3.cpp – KG6ZVP

+0

私のコマンドラインの最後に-lboost_filesystemを追加しました:g ++ -o pr3 pr3.cpp -lboost_filesystem しかし、私は私のコマンドラインを次のように変更する必要がありますか?/usr/bin/ld:/tmp/ccKa219G.o:シンボル 'boost :: system :: system_category()'への未定義の参照 /usr/bin/ld:ノート: 'boost :: system: :system_category() 'はDSO /usr/lib/libboost_system.so.1.46.1で定義されていますので、リンカのコマンドラインに追加してください。 /usr/lib/libboost_system.so.1.46.1:シンボルを読み取れませんでした:無効操作 collect2:ldは1の終了ステータスを返しました。 – KG6ZVP

+6

@ KG6ZVP: '-lboost_system'も追加しました。 –

関連する問題