how do I write a makefile for program that has test.c file, and a test.h header file?
thanks.
how do I write a makefile for program that has test.c file, and a test.h header file?
thanks.
You'll need a tutorial for makefiles. I'm sure you can find one on the net, but I don't know any good sites. However the general process is as follows:
You have a make target for your program, and a make target for each of the .o files, which correspond to each c file. In this case that means 2 make targets. The program itself must depend on all the c files. The .o file must depend on the .c file it corresponds to and all it's included files.
To specify a make target, provide the name of the target, fallowed by a colon, followed by each of its dependencies. Indent the next line with a tab (not spaces!) and print the command needed to make that target. If multiple commands are needed, use multiple indented lines. Consult your compiler documentation for the commands to build the respective make targets.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
One other thing to note is that make generally understands suffixes. So for instance, technically my makefiles should have targets for newton.o (et cetera) but they don't; make can see newton.c (actually newton.f, but never mind) and knows how to turn .c into .o, so it just does it. (This probably makes me a bad person.) You can also set up a rule for *.o based on *.c. You can find the manual for gnu make at gnu.org. (Of course, if you're not using gnu make, the above is probably right but there are going to be little differences.)
Here's what I used to learn about makefiles:
http://www.gnu.org/software/make/manual/make.html
Although I prefer the PDF version since you can print it out and read it on the bus, or keep it beside your bed in case you can't sleep...
http://www.gnu.org/software/make/manual/make.pdf
quick/dirty GNU Makefile:
NOTE: There MUST be tabs in Makefile, and i couldn't input them here so don't just copy/paste, replace spaces with tabs !!!Code:CFLAGS=-W -Wall all: test.exe test.o: test.c test.h gcc $(CFLAGS) -c test.c test.exe: test.o gcc -o test.exe test.o clean: rm -f test.o test.exe
Hi, Is there any tools to create makemake file.
I hv set of source files and a header file in my program. i need to create a make file for this.
I went through the google to find how to and im still in that phase.
but at the middle of it i found a tool called automake.
What make the difference using a tool to create a make file or writing its by my own.
As a beginer which one would you recommend me?
thanks.
This is a new thread, so if some moderator can help by splitting this and the previous post off, it would help.
Some compilers are able to produce a dependency listing, which is part of generating a makefile. There are tools that go well beyond that - most IDE's have a way that produce a makefile, but it's often just as easy to write the bit that sets up the overall project yourself (because even in the IDE, you have to select which source files get compiled, and place them into some box or such).
It is not hard if you understand a bit of makefile structure. If you don't, then you probably should study a tutorial of makefile structure.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Looks like wwwnuwan started a new thread, so I am closing this old one.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)