尝试编译c ++程序时收到未定义的引用错误。我使用-I
和-L
开关指向lib并包含文件我的命令:
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
答案 0 :(得分: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
。