Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@Savantage

This comment has been minimized.

Copy link

@Savantage Savantage commented Sep 7, 2018

Hello and thanks for the guide. Im getting "access denied" when trying to run the file.
I can compile it, so im able to write files... also I am using the internal memory since I have a tablet with android 5.x

@acnologia000

This comment has been minimized.

Copy link

@acnologia000 acnologia000 commented Mar 8, 2019

chmod u+x 0777

@yoskoslowich

This comment has been minimized.

Copy link

@yoskoslowich yoskoslowich commented Jun 9, 2019

Operation not permitted

@Ldev007

This comment has been minimized.

Copy link

@Ldev007 Ldev007 commented Sep 7, 2019

@yoskoslowich
Have you tried -
termux-setup-storage

?

@Savantage

The problem might be because of the storage access permission because of which you're not able to access file.. have you updated the storage permissions manually for termux before ?

@koouty

This comment has been minimized.

Copy link

@koouty koouty commented Oct 12, 2019

I tried to run a file in c making simply
clang filename.c -o filename but it won't run

@Maxdee-Coder

This comment has been minimized.

Copy link

@Maxdee-Coder Maxdee-Coder commented Nov 12, 2019

Hey, why does it say "Acces denied" when I run a file..?

@francescom

This comment has been minimized.

Copy link

@francescom francescom commented Dec 11, 2019

Because you have ti set execute permissions on the new file:

chmod a+x filename

or

sudo chmod a+x filename

@Frankystar777

This comment has been minimized.

Copy link

@Frankystar777 Frankystar777 commented Feb 15, 2020

What about c++? How to compile?

@francescom

This comment has been minimized.

Copy link

@francescom francescom commented Feb 16, 2020

What about c++? How to compile?

clang filename.cpp -o filename

I guess

@krlan2789

This comment has been minimized.

Copy link

@krlan2789 krlan2789 commented Feb 27, 2020

clang++ filename.cpp -o filename

@JosiasAurel

This comment has been minimized.

Copy link

@JosiasAurel JosiasAurel commented May 2, 2020

Hey please you said how to install GCC compiler in termux but that is clang. I prefer GCC

@VirajKanse

This comment has been minimized.

Copy link
Owner Author

@VirajKanse VirajKanse commented May 2, 2020

Hey please you said how to install GCC compiler in termux but that is clang. I prefer GCC

Gcc isn't available in termux pkgs
U have to deal with clang :V

@pdaxrom

This comment has been minimized.

Copy link

@pdaxrom pdaxrom commented Aug 31, 2020

I added termux repo with gcc 10.2.0 (with fortran)
there how to install it https://cctools.info/index.php/Termux_repository_with_cctools_packages_(gcc_with_fortran_support_etc)

@DebiprasadXD

This comment has been minimized.

Copy link

@DebiprasadXD DebiprasadXD commented Sep 27, 2020

I tried to run a file in c making simply
clang filename.c -o filename but it won't run

gcc filename.c -o filename

@fahadali32

This comment has been minimized.

Copy link

@fahadali32 fahadali32 commented Oct 3, 2020

Can i install some header file by this like color.h etc....

@GogoAkira

This comment has been minimized.

Copy link

@GogoAkira GogoAkira commented Mar 30, 2021

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.

Never mind, no need to chmod anything inside home directory of Termux, it runs fine and already is executable when compiled, but it doesn't work in other directories such as /sdcard which is probably a good thing :)

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Apr 27, 2021

How to link libraries

@Saikatsaha1996

This comment has been minimized.

Copy link

@Saikatsaha1996 Saikatsaha1996 commented Jun 28, 2021

I added termux repo with gcc 10.2.0 (with fortran)
there how to install it https://cctools.info/index.php/Termux_repository_with_cctools_packages_(gcc_with_fortran_support_etc)

Not working

@pdaxrom

This comment has been minimized.

Copy link

@pdaxrom pdaxrom commented Jun 29, 2021

Not working

What are the errors during installation or use?

@Saikatsaha1996

This comment has been minimized.

Copy link

@Saikatsaha1996 Saikatsaha1996 commented Jun 29, 2021

When I removed clang and trying to compile something showing gcc not available...

@Saikatsaha1996

This comment has been minimized.

Copy link

@Saikatsaha1996 Saikatsaha1996 commented Jun 29, 2021

Not working

What are the errors during installation or use?

When I Compile Sgminer showing this problem
OpenCL not found
Lpthread not found
But already available OpenCL and lpthread

Screenshot_2021-06-29-12-40-52-598_com termux

@Saikatsaha1996

This comment has been minimized.

Copy link

@Saikatsaha1996 Saikatsaha1996 commented Jun 29, 2021

Not working

What are the errors during installation or use?

When I Compile Sgminer showing this problem
OpenCL not found
Lpthread not found
C99 no
But already available OpenCL and lpthread

Screenshot_2021-06-29-12-40-52-598_com termux

@Saikatsaha1996

This comment has been minimized.

Copy link

@Saikatsaha1996 Saikatsaha1996 commented Jun 29, 2021

Not working

What are the errors during installation or use?

When I Compile Sgminer showing this problem
OpenCL not found
Lpthread not found
C99 no
But already available OpenCL and lpthread
I already installed php
apt install php
Screenshot_2021-06-29-12-40-52-598_com termux

@Saikatsaha1996

This comment has been minimized.

Copy link

@Saikatsaha1996 Saikatsaha1996 commented Jun 29, 2021

Not working

What are the errors during installation or use?

See this error cc no such file or directory

Screenshot_2021-06-29-15-07-12-938_com termux

@Saikatsaha1996

This comment has been minimized.

Copy link

@Saikatsaha1996 Saikatsaha1996 commented Jun 29, 2021

Not working

What are the errors during installation or use?

See gcc not working
Screenshot_2021-06-29-22-57-43-835_com termux

@Saikatsaha1996

This comment has been minimized.

Copy link

@Saikatsaha1996 Saikatsaha1996 commented Jun 30, 2021

Not working

What are the errors during installation or use?

No solution available ?

@pdaxrom

This comment has been minimized.

Copy link

@pdaxrom pdaxrom commented Jun 30, 2021

Hi, letme check on the weekend, sorry

@Saikatsaha1996

This comment has been minimized.

Copy link

@Saikatsaha1996 Saikatsaha1996 commented Jun 30, 2021

Hi, letme check on the weekend, sorry

Ok thank you
.. I am waiting
🙂

@Saikatsaha1996

This comment has been minimized.

Copy link

@Saikatsaha1996 Saikatsaha1996 commented Jul 1, 2021

Not working

What are the errors during installation or use?

Screenshot_2021-07-01-12-29-36-183_com termux

@Saikatsaha1996

This comment has been minimized.

Copy link

@Saikatsaha1996 Saikatsaha1996 commented Jul 1, 2021

Hi, letme check on the weekend, sorry

See please

When you free please try to slove I will give you report

Screenshot_2021-07-01-20-08-54-692_com termux

@Gustavo10Destroyer

This comment has been minimized.

Copy link

@Gustavo10Destroyer Gustavo10Destroyer commented Aug 27, 2021

Binary files can't run on Internal Storage, only on termux home folder

You need move the output to ~/ and use chmod +x filename

@AbdullahBinJahed

This comment has been minimized.

Copy link

@AbdullahBinJahed AbdullahBinJahed commented Sep 2, 2021

Now GCC is available through its-pointless repo
pkg i gcc-11

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