cor*_*bin 36 c android arm cross-compiling android-ndk
我想使用arm-linux-gnueabi-gcc从C构建静态hello世界,而不是使用NDK独立工具链或代码源.
在Ubuntu ......
我做了以下事情:
sudo apt-get install gcc-arm-linux-gnueabi
Run Code Online (Sandbox Code Playgroud)
我创建了一个像这样的hi.c:
#include <stdio.h>
int main(int argc, char** argv) {
printf("hello world\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我编译它像这样:
arm-linux-gnueabi-gcc -static hi.c -o hi
Run Code Online (Sandbox Code Playgroud)
我在这样的模拟器上运行它:
adb push hi /data/hi
adb shell /data/hi
Run Code Online (Sandbox Code Playgroud)
但是,我得到了这个:
[1] Illegal instruction /data/hi
Run Code Online (Sandbox Code Playgroud)
我忘记了什么步骤?根据过去的经验,这"应该"有效,但我显然搞砸了.
Leo*_*Leo 14
尝试指定架构/ cpu.听起来编译器正在创建具有比模拟器可以处理的更高架构版本的代码.
这可能有效:
arm-linux-gnueabi-gcc -static -march=armv5 hi.c -o hi
Run Code Online (Sandbox Code Playgroud)
它在ubuntu桌面上使用CodeBench编译器对我有用. https://sourcery.mentor.com/sgpp/lite/arm/portal/release2029
只需使用以下命令创建静态二进制文件:
arm-none-linux-gnueabi-gcc -o hello -static hello.c
然后,adb推送你好/数据
转到,adb shell $ ./data/hello这将在终端上打印Hello World.同样可以通过手机完成.使用终端模拟器或SL4A bash shell执行.
如果我在 Debian 机器(在我的例子中是 VM)上执行此操作,一切似乎都很好。我不确定在 ubuntu 上做类似的事情会出现什么问题。可能正如 Leo 所建议的那样,但我无法确认。不过这应该对你有用。
http://www.cnx-software.com/2012/01/16/installing-emdebian-arm-cross-toolchain-in-debian/
有人添加了此链接,但它没有使用我在描述中提到的工具链。留下它以防有人感兴趣。
http://tariqzubairy.wordpress.com/2012/03/09/arm-binaries-static-library-for-android/
| 归档时间: |
|
| 查看次数: |
59223 次 |
| 最近记录: |