2

I'm using my Ubuntu 14.10 x64 PC to cross compile to run my programs in my Beaglebone Black but I'm getting a strange error when I try to run the compiled program in my BBB.

The command lines bellow show how I'm doing all steps:

  • PC:writing the code → compiling with arm-linux-gnueabi-gcc → transfering to BBB through sftp

    cleber@cleber:~/test1$ nano ./test1/test1.c
    
    cleber@cleber:~/test1$ more test1.c
    #include "stdio.h"
    
    int main(void) {
      printf("Hello world !\n");
      return 0;
    }
    
    cleber@cleber:~/test1$ arm-linux-gnueabi-gcc test1.c -o test1
    
    cleber@cleber:~/test1$ file test1
    test1: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=ee8c02a051254b2acb7b9054e4599a495da26415, not stripped
    
    cleber@cleber:~/test1$ sftp [email protected]
    [email protected]'s password: 
    Connected to 192.168.7.2.
    sftp> put /home/cleber/test1/* /home/debian/test1
    Uploading /home/cleber/test1/test1 to /home/debian/test1/test1
    /home/cleber/test1/test1                                                                                      100% 8416     8.2KB/s   00:00    
    Uploading /home/cleber/test1/test1.c to /home/debian/test1/test1.c
    /home/cleber/test1/test1.c                                                                                    100%   81     0.1KB/s   00:00    
    sftp> exit
    
  • Beaglebone / through SSH: (running the compiled code received)

    debian@beaglebone:~/test1# chmod +x test1
    
    debian@beaglebone:~/test1$ ls -la
    total 32
    drwxr-xr-x  2 debian debian 4096 Mar  2 01:13 .
    drwxr-xr-x 13 debian debian 4096 Mar  2 01:08 ..
    -rwxr-xr-x  1 debian debian 8416 Mar  2 01:11 test1
    -rw-r--r--  1 debian debian   81 Mar  2 01:11 test1.c
    
    debian@beaglebone:~/test1$ ./test1
    -bash: ./test1: No such file or directory
    
  • But when I compile in the BBB it works:

    debian@beaglebone:~/test1$ gcc test1.c -o test12
    
    debiandebian@beaglebone:~/test1$ ls -la
    total 32
    drwxr-xr-x  2 debian debian 4096 Mar  2 01:30 .
    drwxr-xr-x 13 debian debian 4096 Mar  2 01:08 ..
    -rwxr-xr-x  1 debian debian 8416 Mar  2 01:11 test1
    -rw-r--r--  1 debian debian   81 Mar  2 01:11 test1.c
    -rwxr-xr-x  1 debian debian 5048 Mar  2 01:30 test12
    
    debian@beaglebone:~/test1$ ./test12
    Hello world !
    
    debian@beaglebone:~/Desktop/test1$ file test1 test12
    test1:  ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=0xa0028cee2a4b255154907bcb499a59e41564a25d, not stripped
    test12: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, BuildID[sha1]=0x6a05d95c39cc59d2d407655778dc2ef6f53f02cd, not stripped
    
    debian@beaglebone:~/Desktop/test1$ ldd test1 test12
    test1:
        not a dynamic executable
    test12:
        libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6e1e000)
        /lib/ld-linux-armhf.so.3 (0xb6f15000)
    

May this problem is caused because is used a x64 arch to cross compile a 32bits executable? I installed some libs of 32bits but I'm not sure if I did it correctly. I even have no idea if it's the correct cause of the problem.

Maybe these informations below are useful:

PC:

cleber@cleber:~/test1$ cat /etc/issue.net; uname -ar
Ubuntu 14.10
Linux cleber 3.16.0-44-generic #59-Ubuntu SMP Tue Jul 7 02:07:39 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

BBB:

cat /etc/issue.net; uname -ar
Linux beaglebone 3.8.13-bone70 #1 SMP Fri Jan 23 02:15:42 UTC 2015 armv7l GNU/Linux

I'm newbie with Linux and I'm stuck in this step and unfortunately i really need to resolve it quite fast :'( I hope to get some help here!

Tks in advanced!

14
  • 1
    Could you post file test1 test12 output in beagle system?
    – user.dz
    Sep 21, 2015 at 4:35
  • 1
    There was a related question/answer in SO.
    – Hi-Angel
    Sep 21, 2015 at 4:41
  • @Sneetsher I edited the question to increment you require. They are equal :'( . Tks for replying! Sep 21, 2015 at 5:09
  • 1
    @Sneetsher, @Hi-Angel, Great! You resolved my problem with terminal but i've the same issue using Eclipse. Probably -static would work as well but I've no idea where I've to put -static on eclipse. Do you know? Sep 21, 2015 at 5:32
  • 1
    @Sneetsher, I did as you said. After delete, recompile and transfer it, the result was a not a dynamic executable. I added this step in the main post in the end of the 3th code. this result seems the an issue, right? would be interesting to fix it? btw, after I'm done with all steps I'll conclude this topic answering my own question to help other people. Sep 21, 2015 at 23:09

2 Answers 2

1

Solution:

Just compile the code statically:

PC:

cleber@cleber:~/test1$ arm-linux-gnueabi-gcc -static test1.c -o test1

cleber@cleber:~/test1$ sftp [email protected]
[email protected]'s password: 
Connected to 192.168.7.2.
sftp> put /home/cleber/test1/* /home/debian/test1
Uploading /home/cleber/test1/test1 to /home/debian/test1/test1
/home/cleber/test1/test1                                                                                      100% 8416     8.2KB/s   00:00    
Uploading /home/cleber/test1/test1.c to /home/debian/test1/test1.c
/home/cleber/test1/test1.c                                                                                    100%   81     0.1KB/s   00:00    
sftp> exit

BBB:

debian@beaglebone:~/test1$ ./test1
Hello world !

As you can see, the cross compiled executable test1 is static: test12 was compiled by gcc on BBB just to compare.

debian@beaglebone:~/Desktop/test1$ ldd test1 test12
test1:
    not a dynamic executable
test12:
    libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6e12000)
    /lib/ld-linux-armhf.so.3 (0xb6f09000)

debian@beaglebone:~/Desktop/test1$ file test1 test12
test1:  ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.32, BuildID[sha1]=0x8d34ee7f6f2798fa153dea185f77443d06b6ab61, not stripped
test12: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, BuildID[sha1]=0x6a05d95c39cc59d2d407655778dc2ef6f53f02cd, not stripped

Thanks all for helping!

0

I Had the exactly same issue so i did following

sudo apt-get install g++-arm-linux-gnueabihf

sudo apt-get install gcc-arm-linux-gnueabihf

After this i configure my compilation tools in eclipse to point to the above installed directory and complied the program

After compiling i copy the executable into beagle bone black rev c and executed there through command line and it started working :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .