为什么我使用静态库编译和链接是正确的,而动态库是错误的
why I use the static library to compile and link is corrent while the dynamic library is wrong for am ace demo?
我的gcc/g++版本是4.1.2,ACE-6.10在CentOS5.10中,我用static_libs=1选项制作了ACE库来获取静态库,在制作和制作安装后,我获得了libACE.so、libACE.a等库,然后我编写了以下代码进行测试,代码如下:
#include <ace/Log_Msg.h>
#include <ace/OS_main.h>
using namespace std;
int ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
ACE_DEBUG( (LM_DEBUG, ACE_TEXT("Hello World!n") ) );
return 0;
}
然后我使用以下两种方法进行编译和链接:
方法1:
g++ -p -o acetest acetest.cpp /usr/local/src/ACE_wrappers/lib/libACE.a -I$ACE_ROOT -I$ACE_ROOT/ace -pthread -ldl -lrt
方法2:
[root@localhost testCode]# g++ -p -o acetest acetest.cpp -L/usr/local/src/ACE_wrappers/lib -lACE -I$ACE_ROOT -I$ACE_ROOT/ace -pthread -ldl -lrt
/tmp/cc0eKwlC.o: In function `main':
acetest.cpp:(.text+0x15): undefined reference to `ACE_Log_Msg::last_error_adapter()'
acetest.cpp:(.text+0x1d): undefined reference to `ACE_Log_Msg::instance()'
acetest.cpp:(.text+0x3f): undefined reference to `ACE_Log_Msg::conditional_set(char const*, int, int, int)'
acetest.cpp:(.text+0x57): undefined reference to `ACE_Log_Msg::log(ACE_Log_Priority, char const*, ...)'
collect2: ld 返回 1
问题来了,使用静态库的方法1是正确的,为什么使用动态库的方法2是错误的?
渴望答案,感谢所有人;
编译应用程序时,应向编译器添加-DACE_AS_STATIC_LIBS
标志,以指示您希望与ACE 静态链接
尝试将no_hidden_visibility=1
添加到platform_macros.GNU
文件中。我相信ACE在构建共享库时默认会隐藏符号。
请参阅此处了解它可以提供的好处。然而,当混合静态库和动态库时,它似乎不能很好地工作。如果有人有更多关于原因的信息,请随时插话。
相关文章:
- C++ 动态数组每次添加时将大小增加 1 - 错误
- 动态类的分段错误(家庭作业问题)
- 0xC0000005:访问冲突写入位置0xCDCDCDCD动态分配错误
- 释放动态内存时C++错误
- 从 C 可执行文件加载动态库时收到错误C++"undefined symbol"
- 使用动态数组时C++逻辑错误
- 类动态数组错误
- 尝试从动态分配的二维数组 C++ 中读取值时出现分段错误,并在尝试删除它时给出 munmap_chunk():
- 寻找最小楼梯成本的动态规划问题的错误答案
- 第一次尝试使用new动态创建结构数组,程序挂起没有错误
- 动态 2D 阵列.为什么分段错误?
- 动态内存分配错误
- JNI 不满意链接错误: 动态链接库 (DLL) 初始化例程失败
- 导致堆缓冲区错误的动态分配数组的析构函数
- 如何修复访问动态数组中结构中的字符串变量时"segmentation fault (core dumped)"错误
- 删除动态数组会导致运行时错误
- 使用动态数组对算法编译器错误进行排序
- 我正在尝试使用回溯来解决 N queen 问题,但在编译时它会给出运行时错误(动态堆栈缓冲区溢出)
- 导入错误:动态模块未定义初始化函数
- 分割错误c++动态数组