【问题标题】:Weird Error - Undefined reference while linking to own library gcc奇怪的错误 - 链接到自己的库 gcc 时未定义的引用
【发布时间】:2019-02-12 21:23:39
【问题描述】:

我在创建和链接库方面几乎没有经验,但这次我为这个愚蠢的事情发疯了。

-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

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

-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。

【问题讨论】:

  • 显示用于构建libbbbmds.so的命令行。

标签: gcc g++ linker-errors


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-04
    • 1970-01-01
    • 2012-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多