I understood that it is not possible to run C code with gcc for a file in sdcard directories, sudo is required. But I see that it's possible to run Ruby files with Ruby. I don't understand why. Can someone say me what languages can be run in sdcard in the terminal?

Dani AI

Generated

Short answer for (and building on ): Ruby (and other interpreted languages) can appear to “run” from /sdcard because the interpreter itself (the Ruby binary installed under Termux’s private files) is what the kernel executes; that interpreter reads and interprets the script file on /sdcard. A compiled C/C++ program is an ELF binary the kernel must load and execute, and Android exposes shared/external storage through sdcardfs/FUSE with the noexec behavior and FAT-like semantics that don’t support UNIX exec bits, chmod, or symlinks — so you cannot run ELF executables directly from /sdcard on an unrooted device. (github.com)

Practical, reliable workflow: edit or store sources on the shared storage if you like, but copy them into Termux’s private area before compiling and running. Termux’s home/private directories are on an ext4/f2fs-like area that supports executables and symlinks. Example workflow (run inside Termux):

cp /storage/emulated/0/projects/foo.c $HOME/
cd $HOME
clang -o foo_out foo.c
./foo_out

This keeps compile/link artifacts where exec permissions are allowed. ()

Extra tips and cautions: interpreted runtimes (Ruby, Python, Node) can be invoked on a script that lives on /sdcard because the runtime binary runs from Termux and reads the script, but executing code from shared storage is a security risk (other apps can modify files). Android’s scoped-storage and OEM behavior (Android 10/11+) also affect what you can access, and without root you cannot change mount flags or make /sdcard executable — the only real fixes are compiling/run inside Termux’s $HOME or using a rooted device / properly mounted ext partition. If compilation “worked yesterday,” check where the binary actually ended up (Termux $HOME vs /sdcard) and confirm you’re invoking the compiler inside Termux and not trying to exec a binary that lives on emulated external storage. (source.android.com)

Recommended Answers

All 7 Replies

https://www.google.com/search?q=c+compiler+for+android finds other compilers. Why must it be gcc? Also you wrote C and not C++.

It needs to be written that Android is not like your full size OSes like Linux. Once in a while you run into someone that wants Android and iOS to be a full fledged OS.

Also, https://gist.github.com/VirajKanse/1c0db872cd7685632c02f8826397f190 notes other issues, commands. Not GCC but clang.

Thanks so much. Your second link did help me a lot. It works perfectly.

But afterwards I tried to run a file after entering with cd in the directory where snippets are stored, I typed " clang filename.c -o filename" and the code was not compiled. I don't understand what would changed.

Just my guess. Permissions. Check the file permissions, ownership, etc.

I found this

https://stackoverflow.com/a/40702663/4398376

They say that one cannot run in sdcard

I have unrooted device.

I am persued it was working yesterday.

Since you can not repeat your success, then you have to try it per the methods folk tell you it does work. My thought is this is not to be. You are trying to push the limits of this system and it is pushing back.

Why not use your PC for learning C and such?

Thanks anyway!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.