Search code examples
carmnativecross-compiling

Cross Compile or Compile Native for CPU Arch


When writing software that is CPU arch dependent, such as C code running on x86 or C code running on ARM CPUs. There generally is two ways to go about compiling this code, either Cross-Compile to the ARM CPU arch (if you're developing on an x86 system for example) or copy your code to a native arch CPU system and compile it natively.

I'm wondering if there is a benefit to the native approach vs the cross-compile approach? I noticed that the Fedora ARM team is using a build-server cluster of slow/low power ARM devices to "natively" compile their Fedora ARM spin... surely a project backed by Red Hat has access to some powerful build servers running x86 CPUs that could get the job done in 1/2 the time... so why their choice? Am I missing something by cross-compiling my software?


Solution

  • No technically you're not missing anything by cross-compiling within the context of .c -> .o -> a.out (or whatever); A cross compiler will give you the same binary as a native compiler (versions etc. notwithstanding)

    The "advantages" of building natively come from post-compile testing and managing complex systems.

    1) If I can run unit-tests quickly after compiling I can get to any bugs/issues quickly the cycle is presumably shorter than the cross-compiling cycle;

    2) if I am compiling some target software that has 3rd-party libraries that it uses, then building, deploying and then using them to build my target would probably be easier on native platform; I don't want to deal with the cross-compile builds of those because half of them have build processes written by crazy monkeys that make cross compiling them a pain.

    Typically for most things one would try to get to a base build and the compile the rest natively. Unless I have a sick set up where my cross compiler is super wicked fast and I the time I save there is worth the set up required to make the rest of the things (such as unit testing and dependencies management) easier.

    At least those are my thoughts