Run C plus plus Program on android with termux - Computer Bits Daily

Termux is an Android terminal emulator.

The answer to the question "How to create and run C++ program in an Android device?",  Is here.

To run C++ programs in android using Termux requires the installation of two termux packages.

- clang :

The clang tool is a front-end compiler that is used to compile programming languages such as C, C++, Objective C and Objective C++ into machine code.

- Nano :
Text Editor to create a file.

After installing clang and Nano packages on an android phone. You're ready to run c++ using termux.

Compiling C/C++ in Termux


    Before we learn How to run the C plus plus program on android, let's take a look at Some Important Termux commands we must remember:

    - To clear all screen content run the command.

    $ clear

    - To find the current working directory.

    $ pwd

    - To change our current working directory to another directory. Here I’m moving in /java directory/folder.

    $ cd /java

    - If you want one directory/folder to move

    $ cd..

    - If you want to get back to two directories use.

    $ cd ../../

    - To Create New File: To Create New Directory/Folder use mkdir commad Stands for make a new directory.

    $ mkdir <new-directoy-name>

    - To Delete Directory/Folder in Termux

    $ rmdir <directory-name>

    - To delete File

    $ rm <file-name>

    Here is How You Can Write and Run C++ Programs on Your Android Devices

    Step 1: Installation of  Termux in android smartphone

    Play Store Version of Termux is Deprecated. Due to Android 10 issues, Termux and its plugins are no longer updated on the Google Play Store and have been deprecated. The most recent version for Android >= 7 was v0.101. It is strongly advised not to install Termux apps from the Play Store any longer.

    Download From:

    - F-Droid : F-Droid is a robot with a passion for Free and Open Source Software (FOSS) on the Android platform.

    Click here to dowload F-Droid and get Termux.

    Github :
    Click here to get termux from Github


    - Now open F-Droid, then update repository.

    - After that serach termux in F – Droid and install Termux app as shown in image below.

    GCC / Clang C/C++ Compiler On Android Using Termux

    Step 2: First of all Update and Upgrade Termux

    - Open Termux

    - To Update Termux type command

    $ apt update

    - To Upgrade Termux type command

    $ apt upgrade

    The answer of "How to install C++ in mobile/in termux"

    Open the Termux app and install the clang and nano package to create and run C plus plus program

    $ apt install clang

    - This will install clang package

    $ pkg install nano

    - This command will install nano text editor if not available.

    Step 4: To create C plus plus program file with .cpp extension

    - Type $ nano learncplusplus.cpp

    - This will
    create learncplusplus.c file and open file in nano text editor.

    - Now write simple C plus plus program in nano text editor as given below.

    #include<iostream>

    using namespace std;

    int main() {

    cout << " I love computer bits daily : Free Computer Learning ";

    return 0;

    }


    - Press Ctrl + s to save file and Ctrl +x to exit nano text editor.

    Step 5: To compile your c++ program.

    Type $ clang++ learncplusplus.cpp -o myoutput command and press Enter

    - Here, The option -o is used to specify the output file name. If we do not use this option, then an output file with name a.out is generated.

    - In the above command myoutput is output filename.

    Step 6: To run your c plus plus program

    $ ./ myoutput

    - In the above command myoutput is file name generated when we compile learncplusplus.cpp file

    - You will get output “I love computer bits daily : Free Computer Learning”

    Step 7: To exit Termux type command

    $ exit

    Learn by Watching Video tutorials on how to create and run C++ in Termux. 

    Possible solution for “E: Unable to locate package clang” Error

    • Solution 1: use $ apt update command and then try to install package

    • Solution 2: use $ pkg upgrade command and then try to install package

    • Solution 3: use $ termux-change-repo command and then try to install package

    • Solution 4: use $ pkg install root-repo command and then try to install package

    • Solution 5: use $ termux-setup-storage command and then try to install package

    I hope you like "How to install and run C++ in Android using Termux". 

    Before you leave, I'd like to invite you to join me on this journey! Follow these to stay up to date on new content.

    Android Free Application:

    Online Computer Courses - Computer Bits Daily

    Facebook Page-

    https://facebook.com/computerbitsdaily/

    Quora Space:

    Quora Space - Computer Bits Daily

    YouTube Channel:

    Computer Bits Daily: Tutorial Tips Tricks

    Telegram:

    https://t.me/computerbits

    👌Keep Learning |💕Keep Sharing | 💪Stay Safe!




    Dear Me- Inspiring Beats...!

    Post a Comment

    0 Comments