Search code examples
linuxgccarmgnu-toolchainlinux-toolchain

Can gcc produce binary for Arm without cross compilation


Can we configure gcc running on intel x64 architecture to produce binary for ARM chip by just passing some flags to gcc and not using a cross compiler.


Solution

  • Short: Nope

    Compiler: gcc is not a native crosscompiler, the target architecture has to be specified at the time you compile gcc. (Some exceptions apply, as for example x86 and x86_64 can be supported at the same time)

    clang would be a native crosscompiler, and you can generate code for arm by passing -target=arm-linux-gnu, but you still cant produce binaries, as you need a linker and a C-library too. Means you can run clang -target=arm-linux-gnu -c <your file> and compile C/C++ Code (will likely need to point it to your C/C++ include paths) - but you cant build binaries.

    Rest of the toolchain: You need a fitting linker and toolchain too, both are specific to the architecture and OS you want to run at.

    Possible solutions: Get a fitting toolchain, or compile your own. For arm linux you have for ex. CrossToolchains if you are on debian, for barebones you can get a crosscompiler from codesourcery.

    Since you were very vague, its not possible to give you a clearer answer