gcc - 奇怪的错误 - 链接到自己的库 gcc 时未定义的引用
问题描述
我在创建和链接库方面几乎没有经验,但这次我为这个愚蠢的事情发疯了。
-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。
解决方案
nm
输出列表MDS::BloombergSource::startSession()
函数作为t
- 具有内部链接的函数。其他翻译单元不提供此类功能。
推荐阅读
- python - 将压缩数组完全从磁盘加载到内存中的智能方法是什么 - 也(同样)压缩?
- arduino - 从自主工作的 Arduino 设备远程接收数据
- mysql - 无法在 MYSQL 中为阿拉伯文本创建 FULLTEXT INDEX
- ios - 无法让 S3 上传在 Xcode 10.2/Swift 中工作
- tensorflow - Unable to load model checkpoint to continue training,Unsuccessful TensorSliceReader constructor: Failed to find any matching files
- html - SVG位置在页面重新缩放时移动
- falcor - 使用 Falcor 发送集合和呼叫请求
- docker - 将微服务移动到不同的主机
- netlogo - Netlogo 在尝试设置播放器时无人问津
- java - 由于未找到列,Hibernate Joined Table 策略多态不起作用