-1

I read a few question on the subject but can't understand any of the answers so I'll ask again. I'm writing a makefile. I need to create a few object files using c files that's in a subdirrectory. and then using this object files to create an exe in the current directory. how do I do that?

ok, this is what I've tried

fansTest.o: map.h list.h fans.h mtm_ex2.h ./tests/fansTest.c

littlerunaway
  • 443
  • 2
  • 8
  • 18
  • 1
    Why don't you try to do it, and then in your question post the attempt and describe why it didn't work? Then we can help you solve the problem. SO is for answering specific technical questions, not providing tutorials. The best thing about software is it's trivial to try things and see what works, and that's how you learn. – MadScientist Dec 14 '13 at 15:04
  • Check this: http://stackoverflow.com/questions/231229/how-to-generate-a-makefile-with-source-in-sub-directories-using-just-one-makefil – JmRag Dec 14 '13 at 15:05

1 Answers1

0

Just use relative paths for your files. For example, if you want to compile source.c from subdir directory, use something like:

gcc subdir/source.c 

instead of

gcc source.c

(obviously, this should be used every time you are reffering to that file and I omitted many aspects of the makefile syntax, but I hope it is clear enough)

Paul92
  • 8,827
  • 1
  • 23
  • 37
  • will something like this work: fansTest.o: map.h list.h fans.h mtm_ex2.h tests/fansTest.c – littlerunaway Dec 14 '13 at 15:11
  • As I do not know your directory structure, I suppose that it is correct. But, when you compile it, you have to use something like: gcc tests/fansTest.c – Paul92 Dec 14 '13 at 15:21
  • if I don't write gcc... he uses default, that's why I didn't put it here. well, "tets" is a subdirectory to the current one – littlerunaway Dec 14 '13 at 15:35
  • 1
    Then it should work, if there is not another problem. What does it say when you run it? – Paul92 Dec 14 '13 at 16:39