opkfix.blogg.se

Makefile for c program with header file
Makefile for c program with header file











makefile for c program with header file

Next, you must ask GCC (or more specifically the C pre-processor) to write the rules to a dependency file, simply add -MD to your CFLAGS. First you must have a list of all the object files in your project, this is often the easiest way to structure project make files anyway.

makefile for c program with header file

With GNU Make and GCC the solution is surprisingly simple. The problem becomes even worse if you consider automatic rules which can create any object file from a similarly named c file. You would have to update the Makefile every time you change the header files which is easy to forget. So, now if either file1.c, header1.h or global_header.h is edited the object file file1.o will be re-built. So for example, if file1.c uses header files header1.h and global_header.h, the rule might look like: file1.o: file1.c header1.h global_header.h This declares that if file1.c is changed, file1.o must be re-made.Īnother dependency that is fairly obvious is header files as dependencies of the object file created from a single source file. Where file1.o is the object file, file1.c is the source file.

makefile for c program with header file

You may be familiar with rules of the form: file1.o: file1.c The main strength of the system is the way you can define the dependencies of each stage and then let Make figure out what's changed (based on file dates) and build all the bits required. GNU Make is still a brilliant tool for managing embedded software project build systems. Automatically detect changes in header files in a Makefile













Makefile for c program with header file