2017-05-29 111 views
0

我剝去項目中的所有類,留下了三個錯誤是這樣的:使用NetBeans IDE
提高LIB錯誤在NetBeans

error_code.hpp:222: undefined reference to `boost::system::generic_category() 

點擊文件 - >項目屬性 - >鏈接
旁邊的圖書館,加入libboost_system.so

它擺脫了三個不確定的參考提振::系統:: generic_category()

現在它給:

CLEAN SUCCESSFUL (total time: 123ms) 
cd '/home/michaeleric/NetBeansProjects/NNW' 
/usr/bin/make -f Makefile CONF=Debug 
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf 
make[1]: Entering directory `/home/michaeleric/NetBeansProjects/NNW' 
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/nnw 
make[2]: Entering directory `/home/michaeleric/NetBeansProjects/NNW' 
mkdir -p build/Debug/GNU-Linux/_ext/d028d44d 
rm -f "build/Debug/GNU-Linux/_ext/d028d44d/CGrid.o.d" 
g++ -c -g -MMD -MP -MF "build/Debug/GNU-Linux/_ext/d028d44d/CGrid.o.d" -o build/Debug/GNU-Linux/_ext/d028d44d/CGrid.o ../../Desktop/NN_22_05_17/CGrid.cpp 
mkdir -p dist/Debug/GNU-Linux 
g++  -o dist/Debug/GNU-Linux/nnw build/Debug/GNU-Linux/_ext/d028d44d/CGrid.o -L/usr/include/boost -lboost_system 
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function `_start': 
collect2: error: ld returned 1 exit status 
make[2]: *** [dist/Debug/GNU-Linux/nnw] Error 1 
make[2]: Leaving directory `/home/michaeleric/NetBeansProjects/NNW' 
make[1]: *** [.build-conf] Error 2 
make[1]: Leaving directory `/home/michaeleric/NetBeansProjects/NNW' 
make: *** [.build-impl] Error 2 

BUILD FAILED (exit value 2, total time: 6s) 

這個錯誤的含義是什麼以及如何解決?

類,休息需要

#include </usr/include/boost/thread/thread.hpp> 
#include </usr/include/boost/thread/xtime.hpp> 

#include </usr/include/boost/iostreams/write.hpp> 

#define byte unsigned char 
#define Thread boost::thread 

class CGrid 
{ 

    Thread* GetThread(); 

    bool SetThread(Thread* thread); 

}; 
+0

你的程序沒有'main'功能。 –

+0

謝謝henri。我「應該」知道 –

+0

如果您喜歡我的回答並且有幫助,請考慮通過點擊分數旁邊的箭頭和/或將其標記爲接受的答案(通過點擊複選標記✓)。 –

回答

0

如果我編譯這與

g++ test.cpp -lboost_system 

我得到同樣的連接錯誤這是

/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In function `_start': 
(.text+0x20): undefined reference to `main' 

不過,如果我添加一個空main函數,它編譯好。 (我也取代你的醜#define替代與typedef。)

#include </usr/include/boost/thread/thread.hpp> 
#include </usr/include/boost/thread/xtime.hpp> 

#include </usr/include/boost/iostreams/write.hpp> 

typedef unsigned char byte; 
typedef boost::thread Thread; 

class CGrid 
{ 

    Thread* GetThread(); 

    bool SetThread(Thread* thread); 

}; 

int main() {} 

如果這意味着是一個目標文件,並main是另一個翻譯單位,與-c參數編譯成這樣:

g++ -c test.cpp -lboost_system 
+0

我沒有收到「對'main'」錯誤的未定義引用。並想知道爲什麼#定義是醜陋的? –

+0

@michaeleric也許你有不同版本的鏈接器。關於'#define',請參見[typedef和#define在c中是否一樣](https://stackoverflow.com/questions/1666353/are-typedef-and-define-the-same-in-c) –