我陷入了交叉编译的不那么阳光的世界。
我正在尝试为我的 BeagleBone Black(运行 TI Cortex-A8 处理器)编译一个简单的 hello world 应用程序。
首先,我在 x86 上编译并成功运行了 hello world 应用程序gcc
然后我将编译设置更改为以下内容:
arm-linux-gnueabi-gcc -c -O0 -g3 -Wall main.c -o bin/obj/main.o
arm-linux-gnueabi-gcc bin/obj/main.o -o bin/hello_world
我通过 SCP 将文件传输到 BeagleBone,并设置可执行权限chmod +x hello_world
运行后(./hello_world
),我唯一的回应是:
-bash: ./hello_world: No such file or directory
的输出file
匹配的是/sbin/init
正如我所期望的:
$ file hello_world
hello_world: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=0x24b659b7a41fe043a6f4649d4ebfb5e692ebf0c7, not stripped
$ file /sbin/init
/sbin/init: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, BuildID[sha1]=0xd21f6957ec031a27d567b3d5e6aa14b9e0c30c37, stripped
的结果ldd
is:
$ ldd hello_world
not a dynamic executable
我尝试添加合适的平台和 CPU 类型,将编译更改为:
arm-linux-gnueabi-gcc -c -O0 -g3 -Wall -march=armv7-a -mtune=cortex-a8 main.c -o bin/obj/main.o
arm-linux-gnueabi-gcc bin/obj/main.o -o bin/hello_world
这最初给我带来了一个新错误:Text file busy
,但此后我无法再次恢复该错误,因为它现在返回了No such file or directory
。我猜那个特定的尝试只是一次糟糕的转会或其他什么。