title: Makefile to compile both c and cpp files
body: <p>I would like to compile my program but I have some problems to do so. My program is composed of a main function, written in C. The other files are either .h or .cpp files that I haven't written. I have a make file but unfortunately I cannot compile my program. This is the "architecture" of the files :</p>
  
  <p>a.h only contains definitions of constant.</p>
  
  <p>b.h and b.cpp. b.cpp includes a.h</p>
  
  <p>c.h and d.cpp. c.h contains the signatures of d.cpp's methods. d.cpp includes a.h, b.h and c.h.</p>
  
  <p>The last file is main.c which include c.h.</p>
  
  <p>The makefile I used is the following one :</p>
  
  <pre><code>CXX      = g++
  CXXFLAGS = -Wall -ansi -g
  CC       = gcc
  CCFLAGS  = -g
  OBJS     = main.o a.o b.o c.o
  
  exec : $(OBJS)
      $(CXX) -o $@ $(OBJS)
  
  c.o: d.cpp b.h a.h  
      $(CXX) -c $(CXXFLAGS) $&lt;
  
  a.o: a.h
      $(CXX) -c $(CXXFLAGS) $&lt;
  
  b.o: b.cpp a.h
      $(CXX) -c $(CXXFLAGS) $&lt;
  
  %.o : %.cpp
      $(CXX) -c $(CXXFLAGS) $&lt;
  
  %.o : %.c
      $(CC) -c $(CCFLAGS) $&lt;
  </code></pre>
  
  <p>Can someone me where I'm wrong ? Furthermore, how can I modify the makefile such that I can put a,b,c and d files in a subfolder without causing any problem ?</p>
  
  <p>Thank you !</p>
  
  <p>EDIT :
  This is the error I get :</p>
  
  <pre><code>g++ -o tester main.o a.o b.o c.o
  Undefined symbols for architecture x86_64:
      "_crypto_aead_encrypt", referenced from:
           _main in main.o
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  make: *** [tester] Error 1
  </code></pre>
  
  <p>The function is defined in declared in c.h and defined in d.cpp</p>