Por que uma única compilação cruzada não funciona? Erro: bash: ./test1: Nenhum arquivo ou diretório

2

Estou usando o meu Ubuntu 14.10 x64 PC para atravessar a compilação para executar meus programas no meu Beaglebone Black, mas estou recebendo um erro estranho quando tento executar o programa compilado no meu BBB.

As linhas de comando abaixo mostram como estou executando todas as etapas:

  • PC: escrevendo o código → compilando com arm-linux-gnueabi-gcc → transferindo para BBB através de 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 / através do SSH: (executando o código compilado recebido)

    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
    
  • Mas quando eu compilo no BBB, funciona:

    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)
    

Esse problema é causado porque é usado um arco x64 para compilar um executável de 32 bits? Eu instalei algumas libs de 32bits, mas não tenho certeza se fiz corretamente. Eu nem tenho ideia se é a causa correta do problema.

Talvez essas informações abaixo sejam úteis:

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

Sou novato no Linux e estou nessa etapa e infelizmente preciso resolvê-lo bem rápido: '(espero obter ajuda aqui!

Tks em avançado!

    
por Cleber Marques 21.09.2015 / 06:20

2 respostas

1

Solução:

Apenas compile o código estaticamente:

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 !

Como você pode ver, o executável compilado em cross test1 é estático: test12 foi compilado pelo gcc em BBB apenas para comparar.

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

Obrigado por ajudar!

    
por Cleber Marques 22.09.2015 / 01:58
0

Eu tive exatamente o mesmo problema que fiz depois

  

sudo apt-get instala o g ++ - arm-linux-gnueabihf

     

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

Depois disso eu configuro minhas ferramentas de compilação no eclipse para apontar para o diretório instalado acima e cumpri o programa

Depois de compilar eu copio o executável para o beagle bone preto rev c e o execuo através da linha de comando e ele começou a funcionar:)

    
por user187144 12.01.2016 / 17:47