Multi-source

From emboxit
Revision as of 16:51, 11 September 2015 by Admin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

C

Standard way

MyLib.c:

int Variable;

MyLib.h:

extern int Variable;

main.c:

#include "MyLib.h"
int main(void)
{
   Variable = 10;
   printf("%d\n", Variable);
   return 0;
}






Simple way (proposed by Th.P.)

  • Place c code inside files with names like spi_cpp.h
  • #include spi_cpp.h inside the (main).cpp
  • .h files are not compiled as individual files
  • Compiler 'sees' a single source file
  • Compilers today are fast, so usually no problem with compile time