What is a 'Makefile' and how do I use it?
Whenever I download a source code or example, I usually find no prject file, but a Makefile instead. What does it do and how do I use it?
There are different forms of Makefiles, for example for gnuMake, automake,...
A Makefile is a file with rules for dependencies. Normally it will be used for building libraries and executables from sourcecode.
To use a Makefile you need the right make-Program and you need normally to change some values in the makefile, for example include-paths, compiler-path etc.
A Makefile is a file with rules for dependencies. Normally it will be used for building libraries and executables from sourcecode.
To use a Makefile you need the right make-Program and you need normally to change some values in the makefile, for example include-paths, compiler-path etc.
Which operating system are you using?
If you're using Windows, I can't help you, although I think the Linux example below may apply too.
Under Linux, Makefiles are part of the de facto standard for the compiler project files. They are used by the UNIX command MAKE to form a coherent executable, so they're similar to project files. The way you spell Prject (could just be a typo), I would assume that you might be using Anjuta, and Anjuta (along with KDevelop, and, I think, Borland C++) has no problems with importing makefiles - you should have no problem creating a standard project file out of them.
J
If you're using Windows, I can't help you, although I think the Linux example below may apply too.
Under Linux, Makefiles are part of the de facto standard for the compiler project files. They are used by the UNIX command MAKE to form a coherent executable, so they're similar to project files. The way you spell Prject (could just be a typo), I would assume that you might be using Anjuta, and Anjuta (along with KDevelop, and, I think, Borland C++) has no problems with importing makefiles - you should have no problem creating a standard project file out of them.
J
Makefiles contain information on what other files a file needs to be created, and the commands to do it.
Simple example:
Then you run 'make all', and make will figure out what needs to be done and start executing commands:
Like magic.
Visual studio has nmake I think, which is mostly the same thing.
Simple example:
# Object files depend on source files%.o: %.c# And the command to create an object file from a source file is this: gcc -c $< -o $@# Our program depends on 3 object filesmyprogram: object1.o object2.o object3.o# And here is the command to link them into a program: gcc $^ -o $@# This is a phony target, it will cause myprogram to be created.all: myprogram
Then you run 'make all', and make will figure out what needs to be done and start executing commands:
gcc -c object1.c -o object1.ogcc -c object2.c -o object2.ogcc -c object3.c -o object3.ogcc object1.o object2.o object3.o -o myprogram
Like magic.
Visual studio has nmake I think, which is mostly the same thing.
I assume you enter it in that big black box with scary looking words and flashing square cursor that few dare to enter that often gets mistaken for DOS.
How to enter this mysteryous world from Windows:
Press enter.
How to enter this mysteryous world from Windows:
- Press Windows Key+R together.
- Type
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement