现在的位置: 首页 > 综合 > 正文

C++运行库版本问题

2013年11月11日 ⁄ 综合 ⁄ 共 1481字 ⁄ 字号 评论关闭

问题描述:

  1. 编译时没有问题,成功编译目标文件arrowpig
  2. 程序启动时,系统报错:

ld.so.1: arrowpig: fatal: relocation error: file
/view/jianxu1_arrowpig/vobs/Voyager/framework/arrowpig: symbol
_ZNSs4_Rep26_M_set_length_and_sharableEj: referenced symbol not found

Program terminated with signal SIGKILL, Killed.

 

问题解决步骤:

-bash-3.00$ gc++filt
_ZNSs4_Rep26_M_set_length_and_sharableEj
std::basic_string<char,
std::char_traits<char>, std::allocator<char>
>::_Rep::_M_set_length_and_sharable(unsigned int)

std::string,
我们基本确定这是C++运行库内的符号,在Solaris下,C++的运行库为libstdc++.so。

 

检查一下我的应用程序在运行时所加载的C++运行库:

-bash-3.00$ ldd arrowpig | grep libstdc++
        libstdc++.so.6
=>        /usr/sfw/lib/libstdc++.so.6

-bash-3.00$ nm /usr/sfw/lib/libstdc++.so.6 | grep
_ZNSs4_Rep26_M_set_length_and_sharableEj
-bash-3.00$

可见,应用程序默认加载的c++运行库中没有_ZNSs4_Rep26_M_set_length_and_sharableEj这个符号。但是为什么编译的时候是对的呢,所以现在的推测就是编译的时候所使用的路径和运行时不一致,gcc中使用
-L 来制定运行库路径。

 

 

-bash-3.00$ grep ‘-L’ Makefile

然后我找到了
-L${VOYAGER_ROOT}/lib/${PLATFORM},接着我在/view/jianxu1_arrowpig/vobs/Voyager/lib/x86目录下果然找到了另一个libstdc++.so.6

 

-bash-3.00$ pwd
/view/jianxu1_arrowpig/vobs/Voyager/lib/x86

-bash-3.00$ nm libstdc++.so.6 | grep
_ZNSs4_Rep26_M_set_length_and_sharableEj
[9485]  |    604360|      44|FUNC
|WEAK |0    |2010   |_ZNSs4_Rep26_M_set_length_and_sharableEj

找到了!

 

于是我手工运行:

-bash-3.00$ export
LD_LIBRARY_PATH=/view/jianxu1_arrowpig/vobs/Voyager/lib/x86:$LD_LIBRARY_PATH

-bash-3.00$ ldd arrowpig | grep libstdc++
        libstdc++.so.6
=>        /view/jianxu1_arrowpig/vobs/Voyager/lib/x86/libstdc++.so.6

 

再启动arrowpig, 应用程序正确启动了。

 

 

抱歉!评论已关闭.