在64位环境下执行32位目标文件
我为arm-gcc制作了一个交叉编译工具链,为arm-elf目标配置了binutils、newlib、gcc和gdb。我遇到的问题是,当我在 Mac 上使用 arm-elf-gcc 编译程序时,它生成一个 32 位可执行文件,无法在 64 位环境中执行。
规避这个问题最简单的方法是什么?我可以将 32 位可执行文件放置到 arm 环境中,但我有兴趣知道是否可以以任何方式在 Mac 中执行该文件?
--添加--
我之前就应该这样做,但是让我通知一下,我的程序的目标是 Beagleboard,我期望在 Mac OS X 上使用 arm-gcc 编译并生成对象,并将 *.o 传输到 Beagleboard 以查看输出。唉,当我执行 ./hello.o 时,它在 Beagleboard 上也给出了相同的错误。
谢谢,
萨彦
I made a cross compiling toolchain for arm-gcc, configuring binutils, newlib, gcc and gdb for the arm-elf target. The problem I am having is, when I compile a program with arm-elf-gcc on my Mac, it generates a 32 bit executable with cannot be executed in the 64 bit environment.
What is the easiest way to circumvent this? I could place the 32 bit executables to an arm environment, but I am interested to know if I could execute the file in my Mac in any way?
--Added--
I should have done this before, but let me inform that the target of my program is a Beagleboard, and I was expecting that I would compile and generate the objects using arm-gcc on my Mac OS X and transfer the *.o to the Beagleboard to view output. Alas, it gives the same error on the Beagleboard as well when I do a ./hello.o.
Thanks,
Sayan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有几个问题阻止您在 Mac 上运行可执行文件。
1)架构。您的 Mac 可能是 x86/x86_64 机器(或 PowerPC),但您的二进制文件是针对 ARM 架构编译的(这就是使用交叉编译器的全部意义)。这些指令集不兼容。
2) 您的二进制文件作为 ELF 目标文件链接,而 Mac 使用 Mach-O 目标文件格式。您的操作系统无法加载此可执行格式。
3) 您的可执行文件链接到 newlib (对于某些可能不是 Mac OS 的目标)而不是 Mac OS libc。您的系统调用对于该平台不正确。
如果您的程序是标准的 unix 可执行文件,您可以简单地使用标准系统 gcc 对其进行编译,然后它就会运行。否则,您可以在 ARM 模拟器中运行它,尽管设置起来可能相当复杂。
There are several issues preventing you from running your executable on a Mac.
1) Architecture. Your Mac is probably an x86/x86_64 machine (or PowerPC) but your binary is compiled for ARM architecture (which is the whole point of using a cross-compiler). These instruction sets are not compatible.
2) Your binary is linked as an ELF object file, whereas Macs use the Mach-O object file format. Your OS cannot load this executable format.
3) Your executable is linked against newlib (for some target which is probably not Mac OS) instead of the Mac OS libc. Your system calls are not correct for this platform.
If your program is a standard unix executable, you may be able to simply compile it with the standard system gcc and it will run. Otherwise, you can run it in an ARM emulator, though this may be pretty complicated to set up.
事实上,它是 32 位的并不重要——你不能在 Mac 上执行 ARM 代码(除非你能找到某种 ARM 模拟器)。
The fact that it's 32-bit is irrelevant - you can't execute ARM code on a Mac (unless you can find some kind of ARM emulator).