为什么我使用静态库进行编译和链接是正确的,而动态库对于ace ace演示是错误的?

时间:2016-04-28 11:12:02

标签: c++ ace

我的gcc / g ++版本是4.1.2,在CentOS 5.10中是ACE-6.10,我使用 static_libs = 1 选项制作ACE库以获取静态库,在make和make install之后,我获取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是错误的?

渴望答案,谢谢大家;

2 个答案:

答案 0 :(得分:0)

编译应用程序时,应将-DACE_AS_STATIC_LIBS标志添加到编译器,以指示您要静态链接ACE

答案 1 :(得分:0)

尝试将no_hidden_visibility=1添加到platform_macros.GNU文件中。我相信ACE会默认隐藏符号来构建其共享库。

请参阅here了解其可带来的好处。但是,在混合静态库和动态库时,它似乎不能很好地工作。如果有人知道为什么会这样,请随时加入。