/lib/libncurses.so: undefined reference to `__fdelt_chk@GLIBC_2.15' collect2: ld

在自己的主机上开发的程序移植到其他机器上是一件很烦人的事情,会出现各种不曾在自己机器上出现的问题,昨天移植了一个程序,make的时候报错了:

/lib/libncurses.so: undefined reference to `__fdelt_chk@GLIBC_2.15' collect2: ld

一开始没有理解给出错误的信息,搜索了后才知道是符号表中__fdelt_chk编译的时候使用的是GLIBC_2.15,即2.15版本的GLIBC,为了验证一下,执行

objdump -T lib/libncurses.so.5 |grep '__fdelt_chk'

输出:00000000      DF *UND*    00000000  GLIBC_2.15  __fdelt_chk

__fdelt_chk在libncurses.so.5的符号表里,看一下本机支持的GLIBC版本,执行

strings /lib/libc.so.6 |grep GLIBC_ 

输出:

......
GLIBC_2.7
GLIBC_2.8
GLIBC_2.9
GLIBC_2.10
GLIBC_2.11
GLIBC_2.12
GLIBC_2.13
GLIBC_2.14
GLIBC_2.15
GLIBC_PRIVATE
再到移植的机器上看一下执行结果:

......
GLIBC_2.7
GLIBC_2.8
GLIBC_2.9
GLIBC_2.10
GLIBC_2.11
GLIBC_2.12
GLIBC_PRIVATE
最高只支持到2.12,所以此问题的原因是当前运行系统Glibc版本低于编译环境Glibc版本造成Glibc版造成的。

方法一,

通过在调用fdelt_chk的源代码中加入__asm__(".symver fdelt_chk,fdelt_chk@GLIBC_2.2.5");

此处2.2.5是系统支持fdelt_chk的最低版本,通过执行nm /usr/lib/libc.so.6 |grep "__fdelt_chk"得到,不过我的系统中没有显示出其他低版本。由于需要在源代码中加,而ncurses动态库不是自己编译生成的,没有源文件改,所以此方法不适用。

方法二,

用静态库的方法。

/tmp/ccGUDfOK.o:test.cpp:function main: error: undefined reference to 'initscr' /tmp/ccGUDfOK.o:test.cpp:function main: error: undefined reference to 'cbreak' /tmp/ccGUDfOK.o:test.cpp:function main: error: undefined reference to 'noecho' /tmp/ccGUDfOK.o:test.cpp:function main: error: undefined reference to 'stdscr' /tmp/ccGUDfOK.o:test.cpp:function main: error: undefined reference to 'keypad' /tmp/ccGUDfOK.o:test.cpp:function main: error: undefined reference to 'curs_set' /tmp/ccGUDfOK.o:test.cpp:function main: error: undefined reference to 'stdscr' /tmp/ccGUDfOK.o:test.cpp:function main: error: undefined reference to 'wtimeout' /tmp/ccGUDfOK.o:test.cpp:function main: error: undefined reference to 'endwin' /tmp/ccGUDfOK.o:test.cpp:function Game::draw(): error: undefined reference to 'clear' /tmp/ccGUDfOK.o:test.cpp:function Game::draw(): error: undefined reference to 'stdscr' /tmp/ccGUDfOK.o:test.cpp:function Game::draw(): error: undefined reference to 'wmove' /tmp/ccGUDfOK.o:test.cpp:function Game::draw(): error: undefined reference to 'stdscr' /tmp/ccGUDfOK.o:test.cpp:function Game::draw(): error: undefined reference to 'waddch' /tmp/ccGUDfOK.o:test.cpp:function Game::draw(): error: undefined reference to 'wmove' /tmp/ccGUDfOK.o:test.cpp:function Game::draw(): error: undefined reference to 'waddch' /tmp/ccGUDfOK.o:test.cpp:function Game::draw(): error: undefined reference to 'wmove' /tmp/ccGUDfOK.o:test.cpp:function Game::draw(): error: undefined reference to 'waddch' /tmp/ccGUDfOK.o:test.cpp:function Game::draw(): error: undefined reference to 'wmove' /tmp/ccGUDfOK.o:test.cpp:function Game::draw(): error: undefined reference to 'waddch' /tmp/ccGUDfOK.o:test.cpp:function Game::draw(): error: undefined reference to 'refresh' /tmp/ccGUDfOK.o:test.cpp:function Game::input(): error: undefined reference to 'wgetch' collect2: error: ld returned 1 exit status run.sh: line 2: ./main: No such file or directory
04-04
/tmp/ccURoooa.o:test.cpp:function main: error: undefined reference to 'initscr' /tmp/ccURoooa.o:test.cpp:function main: error: undefined reference to 'cbreak' /tmp/ccURoooa.o:test.cpp:function main: error: undefined reference to 'noecho' /tmp/ccURoooa.o:test.cpp:function main: error: undefined reference to 'stdscr' /tmp/ccURoooa.o:test.cpp:function main: error: undefined reference to 'keypad' /tmp/ccURoooa.o:test.cpp:function main: error: undefined reference to 'curs_set' /tmp/ccURoooa.o:test.cpp:function main: error: undefined reference to 'stdscr' /tmp/ccURoooa.o:test.cpp:function main: error: undefined reference to 'wtimeout' /tmp/ccURoooa.o:test.cpp:function main: error: undefined reference to 'endwin' /tmp/ccURoooa.o:test.cpp:function Game::draw(): error: undefined reference to 'clear' /tmp/ccURoooa.o:test.cpp:function Game::draw(): error: undefined reference to 'stdscr' /tmp/ccURoooa.o:test.cpp:function Game::draw(): error: undefined reference to 'wmove' /tmp/ccURoooa.o:test.cpp:function Game::draw(): error: undefined reference to 'stdscr' /tmp/ccURoooa.o:test.cpp:function Game::draw(): error: undefined reference to 'waddch' /tmp/ccURoooa.o:test.cpp:function Game::draw(): error: undefined reference to 'wmove' /tmp/ccURoooa.o:test.cpp:function Game::draw(): error: undefined reference to 'waddch' /tmp/ccURoooa.o:test.cpp:function Game::draw(): error: undefined reference to 'wmove' /tmp/ccURoooa.o:test.cpp:function Game::draw(): error: undefined reference to 'waddch' /tmp/ccURoooa.o:test.cpp:function Game::draw(): error: undefined reference to 'wmove' /tmp/ccURoooa.o:test.cpp:function Game::draw(): error: undefined reference to 'waddch' /tmp/ccURoooa.o:test.cpp:function Game::draw(): error: undefined reference to 'refresh' /tmp/ccURoooa.o:test.cpp:function Game::input(): error: undefined reference to 'wgetch' collect2: error: ld returned 1 exit status run.sh: line 2: ./main: No such file or directory
04-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值