Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 21st, 2012  |  syntax: None  |  size: 0.90 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Multiple definition and header-only librairies
  2. main.c includes utils.h
  3. vector.c includes utils.h
  4.        
  5. #ifndef UTILS_H_
  6. #define UTILS_H_
  7.  
  8. // and end with:
  9. #endif
  10.        
  11. /tmp/ccOE6i1l.o: In function `compare_int':
  12. ivector.c:(.text+0x0): multiple definition of `compare_int'
  13. /tmp/ccwjCVGi.o:main.c:(.text+0x660): first defined here
  14. /tmp/ccOE6i1l.o: In function `compare_int2':
  15. ivector.c:(.text+0x20): multiple definition of `compare_int2'
  16. /tmp/ccwjCVGi.o:main.c:(.text+0x6e0): first defined here
  17. /tmp/ccOE6i1l.o: In function `matrix_alloc':
  18. ivector.c:(.text+0x40): multiple definition of `matrix_alloc'
  19. /tmp/ccwjCVGi.o:main.c:(.text+0x0): first defined here
  20. ...
  21.        
  22. // header.h
  23. void foo() { }
  24.  
  25. // file1.c
  26. #include "header.h"
  27.  
  28. // file2.c
  29. #include "header.h"
  30.        
  31. #ifndef _FOO_H
  32.   #define _FOO_H
  33.  
  34.   /* some C stuff here */
  35.  
  36.   #endif /* _FOO_H */
  37.        
  38. #include <foo.h>
  39.    #include <bar.h>
  40.    ...
  41.        
  42. #include <foo.h>
  43.    ...