Home > other >  Which stage in C/C compilation process makes it system-dependend?
Which stage in C/C compilation process makes it system-dependend?

Time:11-03

Am going through this tutorial. Is only the linking stage that makes the compilation of c/c code system dependent? Isn't assembly language code generation also system dependent? Isn't system, machine and processor the same thing in this context?

CodePudding user response:

I guess you mean this bit:

Linking is very system-dependent, so the easiest way to link object files together is to call clang on all of the different files that you wish to link together.

What they mean is that the command-line syntax of linking is very system-dependent. You may have to tell the linker explicitly what standard library files should be included, for instance, which varies across platforms. But on all platforms, the clang frontend knows how to invoke the linker correctly. The tutorial is advising you to link via clang instead of invoking the linker directly.

This is certainly not the only system-dependent part of compilation, but other parts are better hidden. Passing a flag like -O2 to clang enables all sorts of CPU-dependent program transformations, but you don't have to tell clang on the command line how to do them.

  • Related