Cross compiling static C hello world for Android using arm-linux-gnueabi-gcc

前端 未结 6 710
盖世英雄少女心
盖世英雄少女心 2020-12-02 06:45

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.

In Ubuntu..

相关标签:
6条回答
  • 2020-12-02 07:03

    Try specifying the architecture/cpu. It sounds like the compiler is creating code with a higher architecture version than the emulator can handle.

    This might work:

    arm-linux-gnueabi-gcc -static -march=armv5 hi.c -o hi
    
    0 讨论(0)
  • 2020-12-02 07:19

    It worked for me with CodeBench compiler on ubuntu desktop. https://sourcery.mentor.com/sgpp/lite/arm/portal/release2029

    Just create a static binary with this command:

    arm-none-linux-gnueabi-gcc -o hello -static hello.c
    

    then push it to phone

    adb push hello /data/local/tmp
    

    go run it:

    adb shell
    $ chmod 755 /data/local/tmp/hello
    $ /data/local/tmp/hello
    

    This will print Hello World on terminal. Same can be done from phone also. Use terminal emulator or SL4A bash shell to execute.

    0 讨论(0)
  • 2020-12-02 07:20

    As far as I know, you cannot run user-land applications within Android that are not compiled with some form of gcc-arm-linux-androideabi.

    0 讨论(0)
  • 2020-12-02 07:21

    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/

    0 讨论(0)
  • 2020-12-02 07:21

    Your code actually works for me.

    I compiled it on Ubuntu and push it to /data/local/tmp

    And then chmod 777 hi

    Finally it works well.

    0 讨论(0)
  • 2020-12-02 07:24

    Did you check the permissions of the data folder ? Try using the local instead ! You can just use adb shell and then cd into the folder where the executable was pushed and try ./hi. I guess this is just a permissions issue

    0 讨论(0)
提交回复
热议问题