1

I'm going to Cross Compile my simple 'Hello World' Program with this toolchain:

arm-hisiv100-linux

and then run on a target which does not have any built-in library.
I have tested my toolchain with and without -static option

arm-hisiv100-linux-gcc HelloWorld.c -o HelloWorld-static -static
arm-hisiv100-linux-gcc HelloWorld.c -o HelloWorld
file HelloWorld-static
     HelloWorld-static: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, not stripped
file HelloWorld
     HelloWorld: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped

My dynamically Program only requires libc.so.0 (which is only a link to libuClibc-0.9.32.1.so) to run,

objdump -x HelloWorld |grep NEEDED
        NEEDED               libc.so.0

and I found it in the toolchain's library

file /opt/hisi-linux-nptl/arm-hisiv100-linux/target/lib/libuClibc-0.9.32.1.so
     /opt/hisi-linux-nptl/arm-hisiv100-linux/target/lib/libuClibc-0.9.32.1.so: ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked (uses shared libs), stripped

but the libuClibc-0.9.32.1.so also have its dynamic dependency

objdump -x /opt/hisi-linux-nptl/arm-hisiv100-linux/target/lib/libuClibc-0.9.32.1.so |grep NEEDED
          NEEDED               ld-uClibc.so.0
file /opt/hisi-linux-nptl/arm-hisiv100-linux/target/lib/ld-uClibc-0.9.32.1.so
/opt/hisi-linux-nptl/arm-hisiv100-linux/target/lib/ld-uClibc-0.9.32.1.so: ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked, stripped

So I copied NEEDED libraries 'libuClibc-0.9.32.1.so' and 'ld-uClibc-0.9.32.1.so' to the target (actually I use NFS), and then modify the LD_LIBRARY_PATH variable.

myTarget # ls
         HelloWorld         HelloWorld-static  HelloWorld.c       libc.so.0 ld-uClibc.so.0
myTarget # chmod +x HelloWorld HelloWorld-static
myTarget # export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/
myTarget # export
         export HOME='/'
         export LD_LIBRARY_PATH='/usr/local/lib:/usr/lib:/mnt/mtd/share/HelloWorldProgram/'
         export LOGNAME='root'
         export OLDPWD='/mnt/mtd/share'
         export PATH='/usr/bin:/usr/sbin:/bin:/sbin'
         export PWD='/mnt/mtd/share/HelloWorldProgram'
         export SHELL='/bin/sh'
         export TERM='vt102'
         export USER='root'

I successfully run HelloWorld-static but not the HelloWorld

./HelloWorld-static
          Hello EveryBody, this is my simple HelloWorld
./HelloWorld
-sh: ./HelloWorld: not found

I have no idea what i've missed

Any idea or help would be appreciated.

Best Regards

Loi Dang

Loi Dang
  • 408
  • 5
  • 23
  • 1
    Have you tried `ldd ./HelloWorld` to see if the dynamic lib dependencies can be resolved? To see what's a "good" output try `ldd /bin/cp` to see the dependencies of the copy statement. libc is a standard library and should always be installed on the arm machine. On my Mint machine it is installed under `/lib/i386-linux-gnu/libc.so.6` and `/lib/x86_64-linux-gnu/libc.so.6`. – Peter Paul Kiefer Nov 03 '15 at 15:25
  • yes, I can not agree with you more that 'libc should be already installed', but my arm box use the static executables and have no shared lib at all. Btw, look like my ldd can only print shared lib for x86, and it gives me this when I tried to analyse my arm-compiled HelloWorld "HelloWorld: not a dynamic executable" – Loi Dang Nov 04 '15 at 01:26
  • 1
    Sorry; my fault. There is no ldd for the arm tool chain. Perhaps this might help you: https://stackoverflow.com/questions/6150000/cross-compiler-ldd. What I also noticed is that, you copied a so.? file and changed the name to so.0. Perhaps that could be a problem. And libc might also have dynamic dependencies which must be resolved. And if you do not have any dynamic libraries on your arm box ... ;-) – Peter Paul Kiefer Nov 04 '15 at 09:49
  • yay, I missed smthing, libc.so.0 which is a link to libuClibc-0.9.32.1.so have a dynamic dependency ld-uClibc.so.0 which is a link to ld-uClibc-0.9.32.1.so. And the ld-uClibc-0.9.32.1.so have no dynamic dependency. Please see my edit, but it still does not works. Btw, readelf and objdump return the same result in my case – Loi Dang Nov 05 '15 at 08:12

0 Answers0