奇怪的错误 - 链接到自己的库gcc时未定义的引用

问题描述 投票:0回答:1

我在创建和链接库方面没什么经验,但这次我对这个愚蠢的事情感到疯狂。

-bash-3.2$ g++ -m32 src/main.cpp -Iinc -lblpapi3_32 -I/tmp/diff/include -L/tmp/diff/lib -lbbbmds
/tmp/ccQCKwnF.o: In function `main':
main.cpp:(.text+0x14e): undefined reference to `MDS::BloombergSource::BloombergSource()'
main.cpp:(.text+0x4ed): undefined reference to `MDS::BloombergSource::startSession()'
main.cpp:(.text+0x555): undefined reference to `MDS::BloombergSource::openService()'
main.cpp:(.text+0x560): undefined reference to `MDS::BloombergSource::authorize()'
main.cpp:(.text+0x5fc): undefined reference to `MDS::BloombergSource::AddSubscription(char const*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, BloombergLP::blpapi::CorrelationId const&)'
main.cpp:(.text+0x655): undefined reference to `MDS::BloombergSource::subscribe()'
collect2: ld returned 1 exit status

确认我的lib引用了这些函数,例如下面

-bash-3.2$ nm /tmp/diff/lib/libbbbmds.so |grep startSession
0000000000002a62 t _ZN3MDS15BloombergSource12startSessionEv

进一步确认,

-bash-3.2$ c++filt _ZN3MDS15BloombergSource12startSessionEv
MDS::BloombergSource::startSession()

也,

-bash-3.2$ file /tmp/diff/lib/libbbbmds.so
/tmp/diff/lib/libbbbmds.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), not stripped

尝试重新排序libs / src。

gcc g++ linker-errors
1个回答
0
投票

nm输出列出MDS::BloombergSource::startSession()函数作为t - 具有内部链接的函数。其他翻译单位无法提供此类功能。

© www.soinside.com 2019 - 2024. All rights reserved.