| 356 | == Cross compiling example |
| 357 | If you wish to compile applications on a development host intended to run on a target with a different architecture (ie you have an x86 host, and an arm64 target like Venice or Newport) you can use Ubuntu's cross toolchain which consits of a gcc cross-compiler, libc, and binutils. |
| 358 | |
| 359 | Example: |
| 360 | * cross compile for ARM64 (Venice / Newport) on X86 Ubuntu host: |
| 361 | {{{#!bash |
| 362 | # install Ubuntu cross-build package |
| 363 | sudo apt update |
| 364 | sudo apt install crossbuild-essential-arm64 # installs gcc as well as binutils and libs |
| 365 | aarch64-linux-gnu-gcc -v # see gcc version if interested |
| 366 | # build a simple app, using shared libraries |
| 367 | cat << EOF >> helloworld.c |
| 368 | #include <stdio.h> |
| 369 | |
| 370 | int main (int argc, char** argv) |
| 371 | { |
| 372 | printf("Hello World\n"); |
| 373 | return 0; |
| 374 | } |
| 375 | EOF |
| 376 | aarch64-linux-gnu-gcc helloworld.c -o helloworld |
| 377 | file helloworld # shows ELF 64-bit LSB shared object, ARM aarch64, dynamically linked with interpreter /lib/ld-linux-aarch64.so.1 |
| 378 | aarch64-linux-gnu-objdump -x helloworld | grep NEEDED # show libs needed on target |
| 379 | }}} |
| 380 | - this was tested on both an Ubuntu bionic dev host (providing gcc-v7.5) as well as an Ubuntu focal dev host (providing gcc-v9.4.0) |
| 381 | * cross compile for ARM32 (Ventana) on X86 Ubuntu host: |
| 382 | {{{#!bash |
| 383 | # install Ubuntu cross-build package |
| 384 | sudo apt update |
| 385 | sudo apt install crossbuild-essential-armel # installs gcc as well as binutils and libs |
| 386 | arm-linux-gnueabi-gcc -v # see gcc version if interested |
| 387 | # build a simple app, using shared libraries |
| 388 | cat << EOF >> helloworld.c |
| 389 | #include <stdio.h> |
| 390 | |
| 391 | int main (int argc, char** argv) |
| 392 | { |
| 393 | printf("Hello World\n"); |
| 394 | return 0; |
| 395 | } |
| 396 | EOF |
| 397 | arm-linux-gnueabi-gcc helloworld.c -o helloworld |
| 398 | file helloworld # shows ELF 32-bit LSB ARM EABI5v1 shared object, dynamically linked with interpreter /lib/ld-linux.so.3 |
| 399 | arm-linux-gnueabi-objdump -x helloworld | grep NEEDED # show libs needed on target |
| 400 | }}} |
| 401 | |
| 402 | |
| 403 | |