Linux 为 ARM 架构编译我的 C++ 代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4740413/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Compiling my C++ code for ARM Architecture
提问by M99
I am a java developer. I have some C++ code to make some system realted calls. This code is compiled on Intel 32-bit platform using GCC (I have make files) and it works fine on regular Intel based 32-bit linux machine. Now I need to run this on a linux OS running on Marvell ARM processor. When I load the shared objects in java I get the following error.
我是一名 Java 开发人员。我有一些 C++ 代码来进行一些系统相关调用。这段代码是使用 GCC 在 Intel 32 位平台上编译的(我有 make 文件),它在常规的基于 Intel 的 32 位 linux 机器上运行良好。现在我需要在 Marvell ARM 处理器上运行的 linux 操作系统上运行它。当我在 java 中加载共享对象时,出现以下错误。
cannot open shared object file: No such file or directory (Possible cause: can't load IA 32-bit .so on a ARM-bit platform)
无法打开共享对象文件:没有这样的文件或目录(可能的原因:无法在 ARM 位平台上加载 IA 32 位 .so)
Please tell me how to resolve this issue. I looked at the GCC options and I found one option to specify the architecture (-march=armv5) and I can't compile with that option.
请告诉我如何解决这个问题。我查看了 GCC 选项,我找到了一个指定架构的选项(-march=armv5),但我无法使用该选项进行编译。
Thanks in advance.
提前致谢。
采纳答案by shodanex
You need more than just a switch, you need a cross-compiler. You can make your own, but probably the easiest way is :
您需要的不仅仅是一个开关,您还需要一个交叉编译器。您可以自己制作,但最简单的方法可能是:
Find the development tools for your board. It probably comes with a development kit that includes a cross-compilation toolchain
If you don't have these, you can try to install a precompiled cross-compilation like the ones provided freely by CodeSourcery
查找适合您的电路板的开发工具。它可能带有一个包含交叉编译工具链的开发工具包
如果你没有这些,你可以尝试安装一个预编译的交叉编译,就像 CodeSourcery 免费提供的那样
Then you have to make the location of your toolchain (look for something like arm-none-linux-gnueabi-gcc) available in your path.
然后你必须在你的路径中提供你的工具链的位置(寻找类似 arm-none-linux-gnueabi-gcc 的东西)。
Cross compiling simple project is then easy, just override the CC variable in your Makefile :
交叉编译简单的项目很容易,只需覆盖 Makefile 中的 CC 变量:
CROSS = arm-none-linux-gnueabi-
CC = $(CROSS)gcc
LD = $(CROSS)ld
回答by Jeff Lamb
Try using the -mcpu=armv5 switch for gcc.
尝试对 gcc 使用 -mcpu=armv5 开关。
回答by Marcello
here is what's written on http://elinux.org/RPi_Software#ARMwiki:
这是在http://elinux.org/RPi_Software#ARMwiki上写的内容:
-Ofast -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s
-Ofast -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s