簡體   English   中英

如何使用NDK編譯Android的現有C程序?

[英]How do I compile an existing C program for Android using NDK?

我正在編寫一個Android應用程序來測試網絡性能,我想在應用程序中使用iPerf。 我可以找到已經為Android編譯的二進制iPerf文件(然后我可以在手機上運行iPerf並收集它的輸出)但我有興趣自己編譯文件。

在這里,有人提供了可用於編譯程序的腳本: http//sourceforge.net/tracker/index.php?func = enter&aid = 3533374&group_id = 128336 &atid = 711373

我知道它需要NDK,但我不知道從哪里開始。 是否有任何好的資源或建議可以幫助我自己編譯(在Windows上,但我也有Cygwin)。 我知道C以及如何在linux上使用GCC,但我不知道從哪里開始。

在此先感謝您的幫助!

啊,這個鏈接有我正在尋找的信息,對於其他任何人... 想要編譯本機Android二進制文件我可以在手機終端上運行

這是對NDK入門的一個很好的討論。

https://stackoverflow.com/questions/5375453/looking-for-a-good-tutorial-on-android-ndk

如果您完成本教程,您將構建自己的NDK“Hello,World”類應用程序。 它很簡單,但它可以幫助您理解NDK。

這是教程的直接鏈接: http//mobile.tutsplus.com/tutorials/android/ndk-tutorial/

在Iperf3上工作

    #!/bin/sh
wget https://dl.google.com/android/repository/android-ndk-r18-linux-x86_64.zip
sudo apt-get install unzip
unzip android-ndk-r18-linux-x86_64.zip
#--arch arm or arm64 https://developer.android.com/ndk/guides/standalone_toolchain
android-ndk-r18/build/tools/make_standalone_toolchain.py --arch arm --api 26 --install-dir=my-toolchain
# Add the standalone toolchain to the search path.
export PATH=$PATH:`pwd`/my-toolchain/bin

# Tell configure what tools to use. aarch64-linux-android
target_host=arm-linux-androideabi #aarch64-linux-android or arm-linux-androideabi
export AR=$target_host-ar
export AS=$target_host-clang
export CC=$target_host-clang
export CXX=$target_host-clang++
export LD=$target_host-ld
export STRIP=$target_host-strip

# Tell configure what flags Android requires.
export CFLAGS="-fPIE -fPIC"
export LDFLAGS="-pie"
sudo apt-get install build-essential git
git clone https://github.com/esnet/iperf
cd iperf/
echo manual edit src/iperf_api.c change to char template[] = "/data/local/tmp/iperf3.XXXXXX";

#--disable-profiling or edit src/Makefile.in deleting "-pg" from iperf3_profile_CFLAGS and iperf3_profile_LDFLAGS
#./configure --host=arm-linux-androideabi CFLAGS=-static CXXFLAGS=-static --disable-profiling 
#make

##iperf2
#sudo apt-get install autotools-dev
#cp /usr/share/misc/config.{sub,guess} .

#adb push src/iperf3 /data/local/tmp
#adb shell chmod 755 /data/local/tmp/iperf3
#adb shell "/data/local/tmp/iperf3 -v"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM