8

i'm trying to install some new software package under openwrt using opkg,and the installation has been successful,and we can see the binary file really exists in the /usr/bin,and i have trird the lld check but turns out the same . as below:

root@OpenWrt /usr/bin [#]# opkg files cfdisk
Package cfdisk (2.25.2-4) is installed on root and has the following files:
/usr/sbin/cfdisk
root@OpenWrt /usr/bin [#]# ls /usr/sbin/
adjtimex                arping                  ethtool                 iptables-save           mkfs.ext3               pppd                    telnetd
airbase-ng              besside-ng              fdisk                   iw                      mkfs.ext4               rate.awk                uhttpd
aireplay-ng             brctl                   hostapd                 iwconfig                modinfo                 rmmod                   wpa_supplicant
airmon-ng               cfdisk                  insmod                  iwlist                  modprobe                samba_multicall         wpad
airmon-zc               chroot                  ip6tables               iwpriv                  nmbd                    smbd                    xtables-multi
airodump-ng             crond                   ip6tables-restore       lsmod                   ntpclient               smbpasswd
airodump-ng-oui-update  dnsmasq                 ip6tables-save          miniupnpd               ntpd                    swapoff
airserv-ng              dropbear                iptables                mke2fs                  odhcp6c                 swapon
airtun-ng               e2fsck                  iptables-restore        mkfs.ext2               pdnsd                   tc
root@OpenWrt /usr/bin [#]# cfdisk
-ash: cfdisk: not found
root@OpenWrt /usr/bin [#]# ./cfdisk
-ash: ./cfdisk: not found
root@OpenWrt /usr/bin [#]# ldd cfdisk
-ash: cfdisk: not found
root@OpenWrt /usr/bin [#]# ldd id
        libcrypt.so.0 => /lib/libcrypt.so.0 (0x77898000)
        libm.so.0 => /lib/libm.so.0 (0x77872000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x7784e000)
        libc.so.0 => /lib/libc.so.0 (0x777e2000)
        ld-uClibc.so.0 => /lib/ld-uClibc.so.0 (0x778bc000)
root@OpenWrt /usr/bin [#]# export
export HOME='/root'
export LOGNAME='root'
export OLDPWD='/usr'
export PATH='/usr/bin:/usr/sbin:/bin:/sbin'
export PS1='\[\033[35;1m\]\u\[\033[0m\]@\[\033[31;1m\]\h \[\033[32;1m\]$PWD\[\033[0m\] [\[\033[35m\]\#\[\033[0m\]]\[\033[31m\]\$\[\033[0m\] '
export PWD='/usr/bin'
export SHELL='/bin/ash'
export SHLVL='1'
export SSH_CONNECTION='192.168.1.152 29105 192.168.1.1 22'
export SSH_TTY='/dev/pts/0'
export TERM='xterm'
export USER='root'
root@OpenWrt /usr/bin [#]# 

thanks.

coder
  • 143
  • 1
  • 3
  • 11
  • 1
    Your cfdisk binary is probably linked to a dynamic linker that does not exist (i.e. something other than ld-uClibc.so.0) Run `readelf -a` on your binary, look for the "program interpreter" – nos Jul 13 '15 at 14:11
  • thanks @nos,the readelf has not install yet..should i copy that file into my ubuntu system witch has readelf then check it out?and i think it's probably caused by linux version.by the way,the "ld-uClibc.so.0" is from the "id" as `lld id` command just for the comparation with `ldd cfdisk`. – coder Jul 13 '15 at 14:41
  • Sure, run readelf on the binary wherever you want. I'm saying that since `ldd id` shows `ld-uClibc.so.0` then that particular library exist. and , your cfdisk is probably not using that, but some other dynamic linker that does not exist on your machine. Possibly due to cfdisk being compiled with another version of uClibc or another C library alltogether. – nos Jul 13 '15 at 17:40

1 Answers1

3

As mentioned by @nos in the comments on the question this can happen if binary is linked with a libc that doesn't exist on your device.

e.g. This is the output I get when I try to run a binary that's been built with the wrong libc (note that I specify the full path /usr/bin/ldd because without that for some reason I was getting the same "not found" error you note in your question).

root@OpenWrt:~# /usr/bin/ldd badbin 
ldd: can't open cache '/etc/ld.so.cache'
checking sub-depends for '/usr/lib/libusb-1.0.so.0'
checking sub-depends for '/lib/libgcc_s.so.1'
checking sub-depends for 'not found'
    libusb-1.0.so.0 => /usr/lib/libusb-1.0.so.0 (0x00000000)
    libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00000000)
    libc.so => not found (0x00000000)
    not a dynamic executable

For me the issue was that I was building my package using the wrong toolchain. I'd assumed that the git://git.openwrt.org/openwrt.git repo was for Chaos Calmer (the current release at time of writing). But of course that repo is the development branch (svn trunk). I needed to use git://git.openwrt.org/15.05/openwrt.git instead.

You can confirm which libc you're building with by checking the name of the toolchain directory staging_dir. The libc version is the last component of the name (e.g. toolchain-mips_34kc+dsp_gcc-4.8-linaro_uClibc-0.9.33.2 is using uClibc-0.9.33.2).

Compare this version to the version of libc that's present on your router by checking what /lib/libc.so* links to on your router (run ls -l /lib/libc.so*). If you need to change the libc version used by your toolchain then do make menuconfig in the OpenWRT buildroot and set the libc version in Advanced configuration options (for developers) -> Toolchain Options -> C Library implementation. You probably shouldn't need to change this setting though -- make sure you're building from the correct source repo for the version installed on your router.

Dave
  • 4,322
  • 1
  • 31
  • 38
  • yeah,it finally work by matching the gcc version,thanks a lot!by the way,i have build other tools for my router using latest gcc and it work by adding gcc option -Wl,-rpath,/boxer/lib -Wl,--dynamic-linker,/boxer/lib/ld-linux.so.3 and put the libc.so etc into a costome place like /boxer/lib/* – coder Oct 13 '16 at 04:15