StackDoc

StackDoc

當前位置: 主頁 > JAVA編程 > ANT >

Android Native C 之 Helloworld的四種編譯方式

時間:2011-08-08 17:36來源:Internet 作者:Internet 點擊:
一.編寫helloworld.c Android.mk     [root@fontlose jni]# cat hello.c #include <stdio

一.編寫helloworld.c Android.mk

    [root@fontlose jni]# cat hello.c

    [root@fontlose jni]# cat Android.mk

二.編譯

    1) 使用NDK r5

          目錄結構  ─ hello
                                ├── jni
                                   ├── Android.mk

                                   └── hello.c

    2) 使用通用toolchain

        在hello.c目錄下

Windows: http://www.codesourcery.com/gnu_toolchains/arm/portal/package3400/public/arm-none-linux-gnueabi/arm-2008q3-41-arm-none-linux-gnueabi.exe
Linux: http://www.codesourcery.com/gnu_toolchains/arm/portal/package3399/public/arm-none-linux-gnueabi/arm-2008q3-41-arm-none-linux-gnueabi.bin

    3) 在源碼環境中編譯

        1. 在源碼development 目錄下創建hello目錄
       2.將helloworld.c Android.mk拷貝至hello目錄下
       3. [root@fontlose Android-2.3]# . build/envsetup.sh

       4. [root@fontlose Android-2.3]# mmm development/hello/

      5.編譯完成執行文件在out/target/product/generic/symbols/system/bin/helloworld
        下載至設備

    4) 使用源碼自帶Toolchain

       在這之前要把上一步中的helloworld模塊clean:
       使用showcommands選項重新編譯helloworld,查看具體命令,從輸出命令行可以看到,Android編譯環境所用的交叉編譯工具鏈是prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-gcc。
       利用上面輸出的編譯命令,簡化來手工編譯helloworld程序,先手工刪除上次編譯得到的helloworld程序:
       gcc編譯,生成目標文件
       生成可執行文件:
       使用了out/host/linux-x86/bin/soslim工具進行STRIP
Android並沒有采用glibc作为C庫,而是采用了Google自己開發的Bionic Libc,通用的Toolchain用來編譯和移植Android 的Linux內核是可行的,因为內核並不需要C庫,但是開發Android的應用程序時,其他Toolchain編譯的應用程序只能采用靜態編譯的方式才能運行,使用靜態方式編譯出來的執行文件都比較大。



From:http://blog.csdn.net/fontlose/article/details/6666671
頂一下
(0)
0%
踩一下
(0)
0%
------分隔線----------------------------
發表評論
請自覺遵守互聯網相關的政策法規,嚴禁發布色情、暴力、反動的言論。
評價:
表情:
驗證碼:點擊我更換圖片
欄目列表
推薦內容
  • SystemImager安裝

          安裝環境 SystemImager服務器:CentOS release5.5 (Fina...

  • JS實現遮罩層效果

    function show(){ var cover = document.getElementById("cover"); ...

  • How to update a module

    I looked for instructions on how to update a Drupal module, but could not find an...

  • sqlite使用

    sqlite常量的定義: const SQLITE_OK = 0; 返回成功 SQLITE_ERROR = 1; SQL錯...

  • bat文件

      bat是dos下的批處理文件。批處理文件是無格式的文本文...

  • Oracle goldgate常用命令

        公司使用Oracle 的goldgate已經半年了,總結一下goldgate的常用...