我有一個C++項目引用(ACE_TAO)庫中的.h和.cpp文件。 (http://www.theaceorb.com/)Eclipse C++引用外部庫(ACE + TAO)
我已經包含了項目GCC C++編譯器和GCC C++鏈接器的庫路徑。
但是,當我嘗試構建我的項目時,我不斷收到錯誤。
undefined reference to ACE_Message_Block::~ACE_Message_Block()
| line 627 external location /home/user/Documents/ACE_wrappers/ace/CDR_Stream.inl
undefined reference to CORBA::ORB~ORB();
| line 45 external location /home/user/Documents/ACE_wrappers/Tao/tao/ORB.inl
這是我自己的項目的頭文件
#ifndef MESSENGERSERVER_H_
#define MESSENGERSERVER_H_
#include <tao/ORB.h> // this is causing the error
class MessengerServer {
public:
MessengerServer();
virtual ~MessengerServer();
private:
CORBA::ORB_var orb; // this is causing the error
1)我已經包含了正確的頭文件和Eclipse是能夠解決的頭文件,所以這一定是我的庫路徑是正確的對?
2)如果我的庫路徑是正確的,爲什麼eclipse無法鏈接到.cpp文件以實現2個方法?我的.h文件和.cpp文件位於相同的文件夾目錄中。 3)我認爲這可能是因爲我沒有在庫路徑中的.o文件,所以我運行'make'並生成.o文件在同一個目錄中,但我仍然得到相同的錯誤。
我錯過/誤解了什麼嗎?提前致謝。
更新: 這裏是用來建立我的項目
g++ -I/home/user/Documents/ACE_wrappers/TAO/
-I/home/user/Documents/ACE_wrappers/ace/
-I/home/user/Documents/ACE_wrappers/
-O0- g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"myMain.d" -MT"myMain.d" -o"myMain.o" "../myMain.cpp"
Finished Building:../MyMain.cpp
g++ -I/home/user/Documents/ACE_wrappers/TAO/
-I/home/user/Documents/ACE_wrappers/ace/
-I/home/user/Documents/ACE_wrappers/
-O0- g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"MyServer.d" -MT"MyServer.d" -o"MyServer.o" "../MyServer.cpp"
Finished Building:../MyServer.cpp
g++ -L/home/user/Documents/ACE_wrappers/TAO/
-L/home/user/Documents/ACE_wrappers/ace/
-L/home/user/Documents/ACE_wrappers/
-o "TAOServer" ./myMain.o ./MyServer.o
./MyMain.o: In function 'ACE_InputCDR:~ACE_InputCDR()':
/home/user/Documents/ACE_wrappers/ace/CDR_Stream.inl:627: undefined reference to ACE_Message_Block::~ACE_Message_Block()
./MyServer.o: In function 'CORBA::ORB:decr_refcount()':
/home/user/Documents/ACE_wrappers/Tao/tao/ORB.inl:45: undefined reference to CORBA::ORB~ORB();
我已經在/ home/user/Documents/ACE_wrappers/ace /和/ home/user/Documents/ACE_wrappers/Tao/tao /中編譯了源文件,並且我已經將這兩個文件添加到了我的庫路徑中。我看到.o對象的ACE_Message_Block和ORB。但是我仍然收到相同的錯誤 –
也檢查您是否在命令行中指定了庫。看到這裏:http://stackoverflow.com/questions/22426574/gcc-undefined-reference-to。如果您沒有按名稱和路徑指定庫,請確保庫本身(完整路徑)也包含在命令行中(任何.o文件)。另外,我可能會考慮查看引發問題的兩個.inl文件。如果您的鏈接設置是正確的,那麼它可能是一個命名空間問題,在這種情況下,用於搜索該類的名稱空間與正確的名稱空間不匹配。 –
也許你應該發佈你的gcc命令行,會有一個大的命令行或多個編譯和/或鏈接命令行。 –