G++ 链接器仅对共享库中的某些函数(不是全部)未定义引用
g++ linker undefined reference to only some functions (not all) from shared library
我正在尝试使用 g++ 链接到 Linux 中的第三方库我的 g++ 命令是
g++ -o "outdir/libmyLib.so.1.0" -Wl,--trace-symbol=_foo_bar_baz -Wl,--no-undefined -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -shared -Wl,--verbose obj_a.o obj_b.o foobarwrapper.o -L/usr/local/lib/foobar `pkg-config --libs gtk+-3.0` -Wl,--start-group -llots -lof -ldeps -lfoobar -lz -ldl -lm -Wl,--end-group
这会从链接器生成未定义的引用
GNU ld (GNU Binutils for Ubuntu) 2.26.1
1> Supported emulations:
1> elf_x86_64
1> elf32_x86_64
1> elf_i386
1> elf_iamcu
1> i386linux
1> elf_l1om
1> elf_k1om
1> i386pep
1> i386pe
1> using internal linker script:
1> ==================================================
1> /* Script for --shared -z combreloc -z now -z relro: shared library, combine & sort relocs */
1>
1> attempt to open /usr/local/lib/foobar/libfoobar.so succeeded
1> /usr/local/lib/foobar/libfoobar.so: definition of _foo_bar_baz
1> /obj/x64/Debug/foobarwrapper.o: In function `foobarwrapper::ThreadEntryRoutine()':
1> /foobarwrapper.cpp:479: undefined reference to `_foo_bar_baz()'
1> collect2: error: ld returned 1 exit status
我从这个库中总共使用了大约 30 个函数,但只有 4 个函数生成链接器错误。
我尝试将 -lfoobar 移动到不同的地方。它要么没有区别,要么所有库函数都无法链接。
我尝试根据类似问题的一些答案/评论将 -lfoobar 添加到编译命令中,但仍然没有爱。
我在这里做错了什么?
用extern "C" {}包装库的标头 #includes 似乎已经完成了这项工作。
相关文章:
- "error: no matching function for call to"构造函数错误
- 什么时候调用组成单元对象的析构函数
- 继承函数的重载解析
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- C++模板来检查友元函数的存在
- 递归函数计算序列中的平方和(并输出过程)
- 对RValue对象调用的LValue ref限定成员函数
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 在C++STL中是否有Polyval(Matlab函数)等价物?
- 为什么使用 "this" 指针调用派生成员函数?
- 将对象数组的引用传递给函数
- 函数调用中参数的顺序重要吗
- C++ 如何将参数绑定到具有相同返回类型的函数,并将它们全部存储在一个容器中
- C++ 中深度嵌套函数的单个捕获全部语句?
- C++ 类析构函数删除部分但不是全部成员数据
- 即使我的函数全部定义,也会在C 中获得不确定的引用
- G++ 链接器仅对共享库中的某些函数(不是全部)未定义引用
- C++从字符串中删除括号的函数不会全部捕获它们
- 通过 WinSock2 API 的单次调用"recv()"函数调用获取全部接收字节