简体   繁体   English

如何使用NDK编译Android的现有C程序?

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

I am writing an Android app to test network performance, and I want to use iPerf in the app. 我正在编写一个Android应用程序来测试网络性能,我想在应用程序中使用iPerf。 I can find binary iPerf files already compiled for Android (and then I can run iPerf on the phone and collect its output) but I'm interested in compiling the files myself. 我可以找到已经为Android编译的二进制iPerf文件(然后我可以在手机上运行iPerf并收集它的输出)但我有兴趣自己编译文件。

Here, someone presents scripts that can be used to compile the program: http://sourceforge.net/tracker/index.php?func=detail&aid=3533374&group_id=128336&atid=711373 在这里,有人提供了可用于编译程序的脚本: http//sourceforge.net/tracker/index.php?func = enter&aid = 3533374&group_id = 128336 &atid = 711373

I know that it requires the NDK but I don't know where to start. 我知道它需要NDK,但我不知道从哪里开始。 Are there any good resources or advice that can help guide me to compiling this on my own (on Windows, but I also have Cygwin). 是否有任何好的资源或建议可以帮助我自己编译(在Windows上,但我也有Cygwin)。 I know C and how to use GCC on linux, but I'm not sure where to start here. 我知道C以及如何在linux上使用GCC,但我不知道从哪里开始。

Thanks for any help in advance! 在此先感谢您的帮助!

啊,这个链接有我正在寻找的信息,对于其他任何人... 想要编译本机Android二进制文件我可以在手机终端上运行

Here is a good discussion of getting started with the NDK. 这是对NDK入门的一个很好的讨论。

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

If you work through the tutorial you will build your own NDK "Hello, World" sort of app. 如果您完成本教程,您将构建自己的NDK“Hello,World”类应用程序。 It's simple but it will help you understand the NDK. 它很简单,但它可以帮助您理解NDK。

Here's a direct link to the tutorial: http://mobile.tutsplus.com/tutorials/android/ndk-tutorial/ 这是教程的直接链接: http//mobile.tutsplus.com/tutorials/android/ndk-tutorial/

Work on Iperf3 在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