

Make searches first for a file named main.o and use it. The dependency here is main.o, so it must be resolved before the execution of the code. If you use objects file you usally start your Makefile like that: all: main.o make clean) or executes the default one (usually all).Įach rule has a name, optional dependencies, and shell code to execute. Your Makefile is read by the make program on invocation. G77 -lc -o fprogram fprogram.o ffunction.o cppfunction2.o Informationįor more information, see this make tutorial from the University of Hawaii.First of all, read an introduction to Makefile. No other files should be touch fprogram.f make `fprogram' is up to we make changes to the source code in fprogram.f andĬppfunction2.C, make should automatically recompile the affected object files, and relink the final executable. G77 -lc -o fprogram fprogram.o ffunction.o cppfunction2.o we make no changes to any of the files and rerun make, This first time through, none of the object files exist at all, and so all the source code files are make Similarly, any object files newer than the final executable will cause the executable to be relinked. Example Compilation with Above MakefileĮach time we run make, any source code files newer than their corresponding object files will be recompiled. Also ensure that there is an extra blank line at the end of the Makefile. Make absolutely certain you prefix each command line (the gcc, g77, or similar lines) with a TAB character, not spaces. In this case, C, C++, and FORTRAN source code is compiled into object files. SUFFIXES: line gives a list of file extensions that will be used in the final compilation.

OBJECTS=fprogram.o ffunction.o cppfunction2.o cfunction2.o The following lines are entered into a normal

Example Makefile to Build Mixed FORTRAN, C, and C++ program
