使用 arm-linux-gnueabi-gcc 为 Android 交叉编译静态 C hello world [英] Cross compiling static C hello world for Android using arm-linux-gnueabi-gcc

查看:52
本文介绍了使用 arm-linux-gnueabi-gcc 为 Android 交叉编译静态 C hello world的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 arm-linux-gnueabi-gcc 从 C 构建一个静态的 hello world,而不是使用 NDK 独立工具链或 Codesourcery.

I want to build a static hello world from C using arm-linux-gnueabi-gcc as opposed to using the NDK standalone toolchain or Codesourcery for that matter.

在 Ubuntu 中...

In Ubuntu...

我做了以下事情:

sudo apt-get install gcc-arm-linux-gnueabi

我创建了一个这样的 hi.c:

I created a hi.c like this:

#include <stdio.h>

int main(int argc, char** argv) {
   printf("hello world\n");
   return 0;
}

我是这样编译的:

arm-linux-gnueabi-gcc -static hi.c -o hi 

我在这样的模拟器上运行它:

I ran it on an emulator like this:

adb push hi /data/hi
adb shell /data/hi

但是,我明白了:

[1]   Illegal instruction     /data/hi

我忘记了哪一步?根据过去的经验,这应该"有效,但我显然搞砸了.

What step have I forgot? Based on past experience this "should" have worked, but I obviously messed this up.

推荐答案

如果我在 Debian 机器(在我的情况下为 VM)上执行此操作,一切似乎都很好.我不确定在 ubuntu 上做类似的事情有什么问题.可能就像 Leo 建议的那样,但我无法确认.不过这应该对你有用.

If I do this on a Debian machine (VM in my case), all seems well. I am not sure what when wrong with doing similar on ubuntu. It could be as Leo suggested, but I cannot confirm. This should work for you though.

http:///www.cnx-software.com/2012/01/16/installing-emdebian-arm-cross-toolchain-in-debian/

有人添加了这个链接,但它没有使用我在描述中提到的工具链.留下它以防万一有人感兴趣.

Someone added this link, but it is not using the toolchain I mentioned in the description. Leaving it in case anyone is interested.

http://tariqzubairy.wordpress.com/2012/03/09/arm-binaries-static-library-for-android/

这篇关于使用 arm-linux-gnueabi-gcc 为 Android 交叉编译静态 C hello world的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆