mashkda.blogg.se

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











makefile for c program with header file

If you have a main.c file in the project directory, running make will automatically compile it to main.o, even though you did not explicitly add any coding to build main.o. # Flag to pass to the C preprocessor all: main.o For example, consider the following makefile:ĬC = gcc CFLAGS = -g # Flag to pass to gcc CPPFLAGS = -I. This feature offers a way to use any flag the user desires, as well as provides a default.

makefile for c program with header file

There are a few benefits to using flags over hard-coded options.įirst, just like any other makefile variable, these flags can be overridden when invoking make from the command line. For example, CFLAGS is used to pass options to the C compiler, while CXXFLAGS is used in conjunction with the C++ compiler. Although you can use any variable for this purpose, make defines some commonly used flags with default values for some common tools, including C and C++ compiler, C preprocessor, lex, and yacc. This is where make flags come into play.įlags in make are just variables containing options that should be passed to the tools used in the compilation process. There is no convenient way to override the options without modifying the makefile. The only way of doing that is to edit the makefile to change the options. But let’s say that you do not wish to pass the -Wall option instead, you want to pass the -Werror option. This snippet compiles main.c to main.o by invoking gcc with the -Wall option.













Makefile for c program with header file