2012-05-12 49 views
9

我嘗試使用g ++ 4.4在Debian上的遠程服務器上使用boost庫編譯小型.cpp文件。我使用Netbeans來達到這個目的。我家的機器是在Windows 7上解決與下一個代碼未定義的引用boost :: timer :: auto_cpu_timer

#include <boost/timer/timer.hpp> 
#include <iostream> 
#include <string> 

int main() 
{ 
    boost::timer::auto_cpu_timer ac; //line 5 
    return 0; //line 6 
} 

聯的一些問題之後,生成2個錯誤:
線5:undefined reference to boost::timer::auto_cpu_timer::auto_cpu_timer(short)'
線6:undefined reference to boost::timer::auto_cpu_timer::~auto_cpu_timer()'

如果

同樣的結果我用頭boost/thread.hpp但是對於線程構造/析構函數。 但是,例如boost/shared_ptr編譯沒有任何問題。在neatbeans 結果編譯命令是

g++ -m64 -I/usr/include/boost/boost_1_49_0 -lboost_system -o dist/Debug/GNU-Linux-x86/test build/Debug/GNU-Linux-x86/main.o 
-L/usr/include/boost/boost_1_49_0/stage/lib -Wl,-rpath /usr/include/boost/boost_1_49_0/stage/lib build/Debug/GNU-Linux-x86/main.o 

我錯過了什麼?

回答

15

您需要鏈接到boost_timer。將-lboost_timer添加到gcc命令行。請查閱Netbeans文檔,瞭解如何將庫添加到項目中。

+1

謝謝,我真的錯過了。 –

+0

您可能還需要-lboost_system(請參閱https://stackoverflow.com/q/41980440/) – ricab

相關問題