Skip to content

Instantly share code, notes, and snippets.

@VirajKanse
Last active January 6, 2025 09:57
Show Gist options
  • Save VirajKanse/1c0db872cd7685632c02f8826397f190 to your computer and use it in GitHub Desktop.
Save VirajKanse/1c0db872cd7685632c02f8826397f190 to your computer and use it in GitHub Desktop.
GCC / Clang C/C++ Compiler On Android Using Termux (Linux Environment)
Install Termux App.
type "apt update"
Then We have to install a text editor to write our code so type "apt install vim" for vim text editor
or u can also use nano text editor for nano type "apt install nano"
Now Clang Installation type "apt install clang" and wait for download completes.
now to create a file simply type vim filename.c or .cpp or nano filename.c or cpp
then u will able to write ur code .
write.....to save ur code simply press esc then type ":wq"
now code is ready to compile
type "clang filename.c -o filename"
If ur code is right then it will be compiled.
Else it will show error.fix it.
To run ur program simply type "./filename".
Tada...Done.
1. apt update
2. apt install vim or nano
3. apt install clang
4. vim/nano filename.
5. clang filename.c -o filename
6. ./filename
@danqdinh
Copy link

Soo I'm here on this old thread. I can't chmod a+x the file, it doesn't change anything. Device isn't rooted, so to execute files device needs to be rooted? Or otherwise how to execute a file since chmod isn't working.

The shared storage is mounted with noexec
copy the file to $HOME to chmod +x

@ZenoArrow
Copy link

Are you sure installing clang will give you GCC? Clang is the name of the LLVM C compiler. LLVM is a competitor to GCC.

@VirajKanse
Copy link
Author

Are you sure installing clang will give you GCC? Clang is the name of the LLVM C compiler. LLVM is a competitor to GCC.

This is 7yr old post mate, I didn't even shit 7yrs ago, anyway it should run a C code fr ;)

@ZenoArrow
Copy link

Are you sure installing clang will give you GCC? Clang is the name of the LLVM C compiler. LLVM is a competitor to GCC.

This is 7yr old post mate, I didn't even shit 7yrs ago, anyway it should run a C code fr ;)

If you want to install GCC on Termux, here's how you can do it...

pkg install tur-repo
pkg install gcc-14 gcc-default-14

That's it. Now you can use GCC to compile code. So instead of "clang filename.c -o filename" you would run "gcc filename.c -o filename".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment