交叉编译ARM二进制文件无法从外部库中找到符号[libncurses]

时间:2014-03-04 09:36:02

标签: linux gcc arm

我正在尝试在Ubuntu 13.04(i386平台)上交叉编译C程序。

我使用以下命令设置我的交叉编译工具链 -

sudo add-apt-repository ppa:ubuntu-toolchain-r/test

sudo apt-get update

sudo apt-get install gcc-4.8-arm-linux-gnueabihf g++-4.8-arm-linux-gnueabihf pkg-config-arm-linux-gnueabihf

我使用posix线程编写了一个小程序,它使用以下命令编译并生成ARM可执行文件 -

arm-linux-gnueabihf-gcc-4.8 thread.c -o thread -lpthread

./file thread command produces 

thread: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=0x960a38d130a451ebb85903b5374894ff364e0633, not stripped

我注意到pthread库是作为工具链安装的一部分安装的。

/usr/arm-linux-gnueabihf/lib/libpthread.so.0

到目前为止一切正常。

现在我尝试使用ncurses库编写如下的小程序。

#include<ncurses.h>

int main()
{
        initscr();
        printw("Hello world\n");
        refresh();
        getch();
        endwin();

        return 0;
}

当我使用下面的命令编译程序时,它找不到ARM的libncurses.so。

/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lncurses
collect2: error: ld returned 1 exit status

我为i386安装了libncurses,我确认我的程序编译并运行i386没有任何问题。

考虑到ARM缺少库,我从 - https://packages.debian.org/en/wheezy/libncurses5 [for ARM]下载了库。我解压缩了debian包并将.so文件复制到libpthread.so所在的同一目录中。

$/usr/arm-linux-gnueabihf/lib: ls -l libncurses.so 

产生

lrwxrwxrwx 1 root root 17 Mar  3 23:07 libncurses.so -> libncurses.so.5.9

现在我再次发出了编译命令,它产生了以下输出 -

 $./arm-linux-gnueabihf-gcc-4.8 curse.c -o curse -lncurses
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/bin/ld: warning: libdl.so.2, needed by /usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so, not found (try using -rpath or -rpath-link)
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/bin/ld: warning: libtinfo.so.5, needed by /usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so, not found (try using -rpath or -rpath-link)
/tmp/ccLCmSAV.o: In function `main':
curse.c:(.text+0x14): undefined reference to `stdscr'
curse.c:(.text+0x18): undefined reference to `stdscr'
curse.c:(.text+0x24): undefined reference to `stdscr'
curse.c:(.text+0x28): undefined reference to `stdscr'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `curscr'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_setupterm'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_set_no_padding'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_getenv_num'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `tputs'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `SP'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_locale_breaks_acs'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `baudrate'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `acs_map'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `putp'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_putp'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_get_locale'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_safe_strcpy'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `cbreak'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_screen_chain'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_doalloc'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_access'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_set_buffer'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `raw'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_keypad'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `unctrl'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_get_screensize'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `tparm'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `noraw'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `tigetflag'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `wtimeout'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_str_init'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `typeahead'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_safe_strcat'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `dlsym@GLIBC_2.4'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_str_copy'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `set_curterm'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_init_acs'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_set_tty_mode'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `COLS'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_outch'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `newscr'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `reset_prog_mode'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `killchar'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `del_curterm'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `def_prog_mode'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_flush'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `def_shell_mode'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `has_ic'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_unicode_locale'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_add_to_try'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `LINES'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `TABSIZE'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_handle_sigwinch'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `nocbreak'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_timed_wait'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_name_match'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_prescreen'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `cur_term'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `flushinp'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `keyok'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `erasechar'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `dlopen@GLIBC_2.4'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `curs_set'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_update_screensize'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `dlclose@GLIBC_2.4'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `reset_shell_mode'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_get_tty_mode'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_globals'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_screen_of'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `tigetstr'
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libncurses.so: undefined reference to `_nc_str_null'
collect2: error: ld returned 1 exit status

我找不到libdl.so,但我的系统已将libtinfo.so.5安装在安装libncurses.so的同一位置。

/usr/arm-linux-gnueabihf/lib$ ls -l libtinfo.so*
lrwxrwxrwx 1 root root     15 Mar  4 00:36 libtinfo.so -> libtinfo.so.5.9
lrwxrwxrwx 1 root root     15 Mar  4 00:37 libtinfo.so.5 -> libtinfo.so.5.9
-rw-r--r-- 1 root root 100976 Mar  4 00:36 libtinfo.so.5.9

那为什么不能找到libtinfo.so.5呢?为什么没有找到libncurses.so中的符号?

请帮忙。

谢谢, - 萨勒曼 〜

0 个答案:

没有答案