Cross Compile Menggunakan Crosstool NG
Install Crosstool-ng
Install required lib
sudo apt install cmake bison autoconf flex texino help2man libtool libtool-bin libtool-doc libncurses5-dev libncursesw5-dev
Clone repository
git clone https://github.com/crosstool-ng/crostool-ng.git
cd crosstool-ng
Install
Install di folder lokal agar tidak memerlukan root permission
./bootstrap
./configure --prefix=${PWD}
make
make install
Build toolchain untuk Raspberry pi 4
Masih di direktori yang sama
./ct-ng armv8-rpi4-linux-gnueabihf
./ct-ng build
Tunggu sampai proses build selesai, toolchain akan terinstall di /home/{user}/x-tool/armv8-rpi4-linux-gnueabihf
Compile untuk raspberry pi 4
Buat contoh program hello world c++:
//hello-world.cpp
#include <iostream>
using namespace std;
int main(){
cout<<"Hello World\n";
return 0;
}
Compile menggunakan toolchain raspberry pi:
xtools/path/armv8-rpi4-linux-gnueabihf/bin/armv8-rpi4-linux-gnueabihf-g++ hello-world.cpp -o hello-world-rpi4
Cek informasi binary yang sudah dibuat (hello-world-rpi4)
file hello-world-rpi4
Hasilnya:
hello-world-rpi4: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 5.13.1, with debug_info, not stripped
Dites menggunakan:
18.04.1-Ubuntu x86_64 GNU/Linux
cmake bison autoconf flex texino help2man libtool libtool-bin libtool-doc libncurses5-dev libncursesw5-dev