Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling C code (netcat) to native Android executable

I'm writing a bash script that uses Netcat to serve framebuffer over network connection, but first I need to compile it to native executable. I even got this script to work on a Ubuntu machine, where netcat is installed by default.

I found this https://github.com/android/platform_external_netcat but have no experience in NDK at all. This obviously doesn't use JNI or Java at all so default approach for making Android applications won't get me anywhere.

So the question is. How do I get an executable file from this source code?

like image 677
Piotrek Okoński Avatar asked Dec 27 '25 21:12

Piotrek Okoński


2 Answers

If anybody else wants to know, this is from the NDK documentation:

SYSROOT=$NDK/platforms/android-<level>/arch-<arch>/
export CC="$NDK/toolchains/<name>/prebuilt/<system>/bin/<prefix>gcc --sysroot=$SYSROOT"
$CC -o foo.o -c foo.c

More specifically, for the netcat from https://github.com/android/platform_external_netcat

SYSROOT=$NDK/platforms/android-19/arch-arm
CC=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc --sysroot=$SYSROOT
$CC -DANDROID -c -o atomicio.o atomicio.c
$CC -DANDROID -c -o netcat.o netcat.c
$CC -o netcat atomicio.o netcat.o

Replace the paths from SYSROOT and CC as appropriate.

like image 83
ctn Avatar answered Dec 30 '25 12:12

ctn


Look in the Android sdk under docs/STANDALONE-TOOLCHAIN.html it describes how to use the ndk as standalone compiler which can produce arm binaries.

like image 26
plaisthos Avatar answered Dec 30 '25 12:12

plaisthos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!