2012-04-02 69 views
0

嘗試編譯C++程序時收到未定義的引用錯誤。我在使用-I-L開關指向lib和include文件我的命令:編譯C++應用程序時出現未定義的引用錯誤

g++ -g -Wall -L/usr/local/lib/active -I/usr/local/include/active tutorial_01.cpp -o tutorial_01 

一些能幫我我缺少什麼嗎?

In file included from /usr/local/include/active/jaus/core/header.h:44:0, 
       from /usr/local/include/active/jaus/core/message.h:49, 
       from /usr/local/include/active/jaus/core/service.h:44, 
       from /usr/local/include/active/jaus/core/transport/transport.h:44, 
       from /usr/local/include/active/jaus/core/component.h:43, 
       from tutorial_01.cpp:42: 
/usr/local/include/active/jaus/core/address.h: In static member function ‘static bool JAUS::Address::IsReservedComponentID(JAUS::Byte)’: 
/usr/local/include/active/jaus/core/address.h:302:40: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses] 
/usr/local/include/active/jaus/core/address.h:303:40: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses] 
/tmp/cczAJw8H.o: In function `main': 
/home/reese/JAUS++-2.110519-src/libraries/jaus++/2.0/src/jaus/core/tutorial_01.cpp:58: undefined reference to `JAUS::Component::Component()' 
/home/reese/JAUS++-2.110519-src/libraries/jaus++/2.0/src/jaus/core/tutorial_01.cpp:78: undefined reference to `JAUS::Discovery::Name' 
/home/reese/JAUS++-2.110519-src/libraries/jaus++/2.0/src/jaus/core/tutorial_01.cpp:78: undefined reference to `JAUS::Component::GetService(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' 
/home/reese/JAUS++-2.110519-src/libraries/jaus++/2.0/src/jaus/core/tutorial_01.cpp:88: undefined reference to `JAUS::Discovery::SetSubsystemIdentification(JAUS::Subsystem::Type, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' 
/home/reese/JAUS++-2.110519-src/libraries/jaus++/2.0/src/jaus/core/tutorial_01.cpp:100: undefined reference to `JAUS::Component::Initialize(JAUS::Address const&, double)' 
/home/reese/JAUS++-2.110519-src/libraries/jaus++/2.0/src/jaus/core/tutorial_01.cpp:109: undefined reference to `CxUtils::Time::GetUtcTimeMs()' 
/home/reese/JAUS++-2.110519-src/libraries/jaus++/2.0/src/jaus/core/tutorial_01.cpp:122: undefined reference to `JAUS::Management::Name' 
/home/reese/JAUS++-2.110519-src/libraries/jaus++/2.0/src/jaus/core/tutorial_01.cpp:122: undefined reference to `JAUS::Component::GetService(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' 
/home/reese/JAUS++-2.110519-src/libraries/jaus++/2.0/src/jaus/core/tutorial_01.cpp:130: undefined reference to `CxUtils::Time::GetUtcTimeMs()' 
/home/reese/JAUS++-2.110519-src/libraries/jaus++/2.0/src/jaus/core/tutorial_01.cpp:136: undefined reference to `CxUtils::Time::GetUtcTimeMs()' 
/home/reese/JAUS++-2.110519-src/libraries/jaus++/2.0/src/jaus/core/tutorial_01.cpp:139: undefined reference to `CxUtils::GetChar()' 
/home/reese/JAUS++-2.110519-src/libraries/jaus++/2.0/src/jaus/core/tutorial_01.cpp:144: undefined reference to `CxUtils::SleepMs(unsigned int)' 
/home/reese/JAUS++-2.110519-src/libraries/jaus++/2.0/src/jaus/core/tutorial_01.cpp:150: undefined reference to `JAUS::Component::Shutdown()' 
/home/reese/JAUS++-2.110519-src/libraries/jaus++/2.0/src/jaus/core/tutorial_01.cpp:58: undefined reference to `JAUS::Component::~Component()' 
/home/reese/JAUS++-2.110519-src/libraries/jaus++/2.0/src/jaus/core/tutorial_01.cpp:58: undefined reference to `JAUS::Component::~Component()' 
collect2: ld returned 1 exit status 
+1

請發佈錯誤信息。 – 2012-04-02 02:15:22

+0

不知道如何添加錯誤消息。我可以修改我原來的問題嗎? – 2012-04-02 02:26:50

+0

當然!只需點擊底部的「修改」鏈接即可。 – 2012-04-02 02:40:17

回答

1

-L選項並沒有真正爲你做些什麼,除非你還使用-l與庫的名稱。我要帶你的庫命名爲libactive.a猜測,在這種情況下,你會想這樣做:

g++ -g -Wall -L/usr/local/lib/active -lactive -I/usr/local/include/active tutorial_01.cpp -o tutorial_01 

如果庫具有不同的名稱,你需要去改變它。

以下是規則:對於名爲/path/to/library/libmylibrary.a的庫,請使用以下命令行:-L/path/to/library -lmylibrary

+0

usr/local/lib/active目錄中有多個共享庫,這就是爲什麼我使用-L – 2012-04-02 02:29:18

+0

您需要爲每個目錄使用'-L'併爲每個庫使用'-l'。 '-L'指定編譯器搜索的目錄,但實際上它不會搜索,除非用'-l'告訴它一個庫的名稱。 – parkovski 2012-04-02 02:32:48

+0

謝謝!我會試試 – 2012-04-02 02:35:38

相關問題