本文介绍了如何编译C code。使用NDK为Android设备(ARM)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要执行以下步骤:


  • 写一个简单的计数器,它不断在C / C ++
  • 溢出后自行复位
  • 编译并推动了code到手机通过ADB

  • 运行它作为通过ADB外壳在后台定期执行

  • write a simple counter that keeps resetting itself after overflow in C/C++
  • compile and push that code into the phone via ADB
  • run it as a regular executable in background via ADB shell

如何使用编译工具链NDK上述C code吗?我发现一对夫妇类似的链接,但他们都不给简单完成步骤这样做。

how to compile the above C code using NDK toolchain? I found a couple of similar links but none of them give simple and complete steps to do so.

如果有完整的步骤请参考我相同的链接。

If there is a link with complete steps please do refer me to the same.

编译环境:Ubuntu的,编译应通过控制台来完成不属于任何IDE

Compile Environment: Ubuntu, compile should be done via console not any IDE

推荐答案

您说得对,我犯了一个错误,我什至没有测试它,并给了我
同样的错误,是由于主的切入点,因为这还没有
改变,但我希望这对你的作品。反正检查符号表纳米,
在实时执行strace的,你甚至可以用gdbserver的。

You're right, I made a mistake, I had not even tested it and gave me thesame error, is due to the entry point of the "main", as this has notchanged but I hope this works for you. Anyway check the symbol table "nm",the real-time execution "strace", you can even use gdbserver.

#include <stdio.h>
int main (int argc, char *argv[])
{
        printf ("hello world");
        return 0;
}


export NDK_ROOT=your_ndk_path
export PATH=$NDK_ROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin:$PATH
export CC=arm-linux-androideabi-gcc
export LD=arm-linux-androideabi-ld
arm-linux-androideabi-gcc -I$NDK_ROOT/platforms/android-18/arch-arm/usr/include -Wl,-rpath-link=$NDK_ROOT/platforms/android-18/arch-arm/usr/lib -Wl,-L$NDK_ROOT/platforms/android-18/arch-arm/usr/lib -Wl,-lc -o test test.c

If ld return with erros like "... ld: error: cannot open... : No such file or directory"
try this for your losed files:
ln -s $NDK_ROOT/platforms/android-18/arch-arm/usr/lib/crtend_android.o
ln -s $NDK_ROOT/platforms/android-18/arch-arm/usr/lib/crtbegin_dynamic.o

这篇关于如何编译C code。使用NDK为Android设备(ARM)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 18:40