Android Developers
Kanalga Telegram’da o‘tish
Here You Can Get Android App Development Tutorials For Free LinkTree https://linktr.ee/androiddeveloperspage Contact Me @androiddevstutorialscommentbot
Ko'proq ko'rsatish808
Obunachilar
Ma'lumot yo'q24 soatlar
+167 kun
+15630 kun
Postlar arxiv
This Is The First Tutorial On How To Compile C++ Code & Generate Executable Binary (.so) File In Android Using Termux By Android Developers Telegram Channel In 2024.
👉 @androiddevstutorials
# For ARM architecture
clang++ -shared -o Calculator_arm.so Calculator.cpp -march=armv7-a
# For ARM64 architecture
clang++ -shared -o Calculator_arm64.so Calculator.cpp -march=armv8-a
# For x86 architecture
clang++ -shared -o Calculator_x86.so Calculator.cpp -march=i686
# For x86_64 architecture
clang++ -shared -o Calculator_x86_64.so Calculator.cpp -march=x86-64Creating Executable Binary (.so) File For Different Processor Architecture (
arm64-v8a, armeabi-v7a, x86) Is Also Possible Using Termux. But As We Are Using Android Device We Can Only Create Executable Binary (.so) File Same As Our Device CPU ABI). For Instance My Device CPU ABI Is arm64-v8a So I Can Only Create Executable Binary (.so) File Only For arm64-v8a.
However If You Want To Go Further You Can Create It With Device That Have Different Processing Architecture Using The Following Commands.
👉 @androiddevstutorialsStep5. After That Save It As A C++ Program Using .cpp Extension File(You Can Give It Any File Name You Want With .cpp Extension).
Step6. Back To Termux & Navigate To The Folder In Which You Save The C++ Program Using The cd Command (Explore More Termux Commands Here).
For Instance I Saved The Calculator.cpp File In My SDCard So I Use The Following Command.
cd /sdcard/
Step7. Now Compile & Convert The C++ Program In To An Executable Binary (.so) File Using The Following Command.
clang++ -shared -o Calculator.so Calculator.cpp
Before We Execute The Following Command Let's Take A Quick Look On It's Pattern.
Calculator.so :- Is The Output Executable Binary (.so) File Name(You Can Name It Anything You Want But With .so Extension).
Calculator.cpp :- Is Your C++ Program File Name.
Note That
It May Take Some Time To Compile & Convert The C++ Program In To An Executable Binary (.so) File Depending On Your Device Processing Power.
After Execution You Will Find The Shared Object (Calculator.so) File At The Same Folder In Which You Save The C++ Program.#include <iostream>
using namespace std;
int main()
{
double Result;
string Operator;
double FirstNumber;
double SecondNumber;
cout << "Enter First Number" << endl;
cin >> FirstNumber;
cout << "Enter Second Number" << endl;
cin >> SecondNumber;
cout << "Enter Operator" << endl;
cin >> Operator;
if (Operator == "+")
{
Result = FirstNumber + SecondNumber;
cout << Result << endl;
cout << "Thank You For Using The Calculator";
}
else if (Operator == "-")
{
Result = FirstNumber - SecondNumber;
cout << Result << endl;
cout << "Thank You For Using The Calculator";
}
else if (Operator == "*")
{
Result = FirstNumber * SecondNumber;
cout << Result << endl;
cout << "Thank You For Using The Calculator";
}
else if (Operator == "/")
{
Result = FirstNumber / SecondNumber;
cout << Result << endl;
cout << "Thank You For Using The Calculator";
}
else
{
cout << "Unknown Operator " << Operator << endl;
}
return 0;
}How To Compile C++ Code & Generate Executable Binary (.so) File In Android Using Termux
Before Diving In To The Todays Post If You Haven't Already Know What Is SO (Shared Object) File & NDK(Native Development KIT) I Recommend You To Check This Post.
To Compile C++ Source Code & Generate SO(Shared Object) File In Android Using Termux Follow The Following Steps.
Step1. If You Don't Have Termux Installed In Your Android Device You Can Install It From Here.
Step2. Also Check The Short Tutorial On Termux If You Are New To It. After That Install C++ Compiler In Your Termux Environment Using The Following Command.
pkg install clang cmake
Step3. After Installing C++ In To Your Termux Environment Verify If It Installed Successfully Using The Following Command.
clang --version
If Installed It Will Print The Version Like This.
clang version 17.0.6
Target: aarch64-unknown-linux-android24
Thread model: posix
InstalledDir: /data/data/com.termux/files/usr/bin
Step4. Prepare You C++ Program That You Want To Convert It To SO(Shared Object) File. For Instance I Created The Following Calculator Program.