DEV Community

Discussion on: How To Run C Programs on Android

Collapse
 
pmcgowan profile image
p-mcgowan • Edited

Stealing the compiler, or ssh'ing over data?

Either way - same answer. These days I use the Termux app (IIRC not available on iPhone), within which you can install openssh and the gcc toolchain which will allow you to ssh and build c programs just as you would on a nix terminal on any desktop.

When I stole the compiler, I had a rooted phone, installed the C4droid app, then went into it's package folder and looked for the binary and linked lib files, copied those into my home folder, made a small wrapper script that added all the necessary compiler flags, and built the c apps from the TerminalIDE terminal.

It's significantly more work (plus trial and error) doing it that way, and requires rooting your phone. Now, with Termux, it's a simple apt-get install -y build-essentials make gcc ... and apt-get install -y openssh-{client,server}.

EDIT: found the old script - left the comments for myself

usage="\
Usage: $(basename $0) [OPTIONS] FILES [-o OUTPUT]
      --libs  use library settings found in file.stdin
  -h, --help  show this menu
~/c4droid/com.n0n3m4.droidc/files/gcc/bin/arm-linux-androideabi-g++ INPUT -lm -ldl -llog -lz -std=c++11 -Wfatal-errors   -lncurses -I~/c4droid/com.n0n3m4.droidc/files/gcc/arm-linux-androideabi/include/ncurses -Wl,-allow-shlib-undefined
"

LIBS=

if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
  echo "$usage"
  exit 1
elif [ "$1" == "--libs" ]; then
  LIBS="-lm -ldl -llog -lz -std=c++11 -Wfatal-errors -lncurses -I~/c4droid/com.n0n3m4.droidc/files/gcc/arm-linux-androideabi/include/ncurses -Wl,-allow-shlib-undefined"
  shift
fi

GPP=~/c4droid/com.n0n3m4.droidc/files/gcc/bin/arm-linux-androideabi-g++
#GCC=~/c4droid/com.n0n3m4.droidc/files/gcc/bin/arm-linux-androideabi-gcc

$GPP $LIBS $*
#$GCC $LIBS $*
exit $?

# droidc/files/file.stdin:
# cd /data/data/com.n0n3m4.droidc/files/gcc/tmpdir
# export TEMP=/data/data/com.n0n3m4.droidc/files/gcc/tmpdir
# /data/data/com.n0n3m4.droidc/files/gcc/bin/arm-linux-androideabi-g++ /data/data/com.n0n3m4.droidc/files/temp.c -lm -ldl -llog -lz -I"/storage/emulated/0/.cfiles/intconv" -std=c++11 -Wfatal-errors   -lncurses -I/data/data/com.n0n3m4.droidc/files/gcc/arm-linux-androideabi/include/ncurses -Wl,-allow-shlib-undefined -o /data/data/com.n0n3m4.droidc/files/temp
# echo "errorcode:$?"
# exit