GCC 链接器:静态 A 在链接其他共享库时看不到静态 B
GCC linker: staticA can't see staticB while linking other shared library
GCC 4.4.3,Ubuntu。
3个项目:
- A(静态库)生成正常
- B(静态库)构建正常
- X(共享库或控制台应用程序)链接器错误
为什么这种情况不让链接X?
X calls B;
B calls A; // WHY???? linker error in X: B has undefined reference to stuff in A
这个案例有效:
X calls A; // this fact allows B access A
X calls B;
B calls A; // Now X linked just fine
完整代码:
//////////////////////////////
// StaticAAA.cpp
void FunctionAAA()
{
}
//////////////////////////////
// StaticBBB.cpp
void FunctionAAA();
void FunctionBBB()
{
FunctionAAA();
}
//////////////////////////////
// App.cpp
void FunctionAAA();
void FunctionBBB();
int main()
{
#ifdef WHY_LINKER_ERROR_FIXED
FunctionAAA();
#endif
FunctionBBB();
return 0;
}
gcc命令行上的库的顺序很重要-您需要按依赖关系顺序列出库。如果您有任何循环依赖关系,那么您可能需要列出至少一个库两次才能满足此要求。
在你的特殊情况下,你可能想要这样的东西:
$ g++ ... X.o -lB -lA ...
相关文章:
- 基于boost的程序的静态链接——zlib问题
- 使用gcc从静态链接的文件中查找可选符号
- 使用转换器提升 Python 问题 - 静态链接
- C++实用程序::转换在静态链接库中不起作用
- 将源中的 GLEW 与 cmake 静态链接
- 在发布模式下启动使用库的静态链接编译的应用程序时出错
- libavdevice 和 x11 的静态链接库应该以什么顺序链接?
- 静态链接启用 PIC 的库时出现链接器 PIC 错误
- 静态链接库时,收到链接器错误:找不到 -lgcc_s
- 静态链接 glibc & boost_python36 for Python extension
- 我可以在C++中配置静态链接吗?
- 协议缓冲区的静态链接会导致与现有符号冲突
- C++标准是否定义了结构中成员函数的函数内定义是否必须具有静态链接?
- 静态链接 Visual Studio dll 到动态链接的 sfml 项目
- 我可以加载与库静态链接的 dll 吗?
- 静态链接MSVC库,动态链接Qt
- C++:找不到静态链接
- OpenSSL AES仅适用于某些计算机,即使具有静态链接也是如此
- CURL 静态链接未解析的外部符号
- 如何强制Windows.h在Visual Studio中静态链接而不是动态链接?