Header content
The Ah header for Ac should contain only the information that is needed for external code using the tools defined in Ac . It should not declare static functions; It should not declare static variables; it should not declare internal types (types used only in Ac ). This should ensure that the file can only use #include "Ah" and then take full advantage of the facilities published by Ac . It should be autonomous, idempotent (so you can enable it twice without compilation errors) and minimal. You can simply verify that the header is self-sufficient by writing #include "Ah" as the first line of #include in Ac ; You can verify that it is idempotent by turning it on twice (but this is best done as a separate test). If it does not compile, it is not autonomous. Similarly for Bh and Bc .
For more information about headers and standards, see “ Should I use #include in headers? ” Which refers to the NASA coding standard, and “ Link to a static library ”, which includes the chkhdr script that I use to test self-sufficiency and idempotency .
compound
Note that main.o dependent on main.c , Ah and Bh , but main.c itself is independent of headers.
When it comes to compilation, you can use:
gcc -o program main.c Ac Bc
If you need other options, add them (most flags at the beginning; libraries at the end, after the source code). You can also compile each file into object code separately, and then link the object files together:
gcc -c main.c gcc -c Ac gcc -c Bc gcc -o program main.o Ao Bo
Jonathan leffler
source share