Today we are going to see how to compile a C++ application for an ARM processor from a computer with x86 or x64 architecture.
To do this, first, we must install the necessary dependencies.
sudo apt-get install libc6-armel-cross libc6-dev-armel-cross binutils-arm-linux-gnueabi libncurses5-dev build-essential bison flex libssl-dev bc
Next, we install the appropriate version of G++ for our ARM architecture. One of the biggest complications is the designation of ARM processors, which determines the necessary dependencies.
If in doubt, this post may be helpful. But, in summary, ARMv7 and earlier processors are 32-bit, while ARMv8 and later are 64-bit (with 32-bit compatibility).
On the other hand, there are cross compilers for software-emulated floating-point operations (like gnueabi) and hardware-implemented floating-point operations (like gnueabihf). If possible to use the second, it is preferred over the first.
So, depending on the type of processor we have, we do the following,
For 32-bit ARM
sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf
For 64-bit ARM
sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
Now, to test, we are going to create a simple “hello world” program. To do this, we create a file ‘main.cpp’ with the following content.
int main(int argc, char *argv[]) {
cout << "Hello world!" << endl;
return 0;
}
To compile it, we run the following command.
For 32-bit ARM
arm-linux-gnueabihf-g++ main.cpp -o hello
For 64-bit ARM
aarch64-linux-gnu-gcc main.cpp -o hello
We move the ‘hello’ file to our target machine, and change the execution permissions (for example, to 777).
We run our test program with the following command.
./hello
If everything went correctly, we should see our “Hello world!” message in the command console.

