Here it finds the target main.obj required at dependency line.We want to make sure that the dependencies are built. Defines a target called mybuild that depends on other targets "main.obj" and "foo.obj".Defines variables that will be used in the compiling and the linking.In addition, any prerequisites that are themselves automatically generated should be updated first. When a target is a file, it needs to be recompiled or relinked if any of its prerequisites change. All make does is execute the recipe we have specified when the target file needs to be updated. It is up to us to supply recipes that will update the target file properly. Note that make does not know anything about how the recipes work. Note that we need to put a tab character at the beginning of every recipe line. A recipe may have more than one command, either on the same line or each on its own line. A recipe is an action that make carries out.A prerequisite is a file that is used as input to create the target.A target can also be the name of an action to carry out, such as clean. A target is usually the name of a file that is generated by a program.In other words, a rule tells make what it's making (target), what it's made from (dependencies), and how to make it (system command). A rule can also explain how and when to carry out an action. make carries out the recipe on the prerequisites to create or update the target. Ī rule explains how and when to remake certain files which are the targets of the particular rule. A simple makefile consists of rules with the following syntax:.There are couple of things we should know about the makefile: So, to use this makefile to delete the executable file and all the object files from the directory, type: Since clean is not a prerequisite of edit, this rule will not run at all if we give the command make with no arguments. To use this makefile to create the executable file called mybuild, type: We will use the previous makefile as a sample. make removes (deletes) mybuild and all object files at make clean.įor more on library (static vs dynamic, dll), see Libraries.As it now has all up-to-date object files for the rule, it executes the command to build mybuild. make looks at the targets foo.obj and compiles these object files in a similar fashion.If not, it runs the command for main.obj by compiling main.cpp to get the object file. If no, as in the example, it checks if main.obj is up to date. make checks whether the prerequisites of main.obj have further dependencies.If yes, as in the example, it runs the rule for first prerequisite, that is, main.obj, to find its dependencies. make next checks if any of the two object files are listed as targets.make runs the rule for first target mybuild and figures its dependencies on main.obj and foo.obj.LIBPATH:$(LIBS) myLib.lib /NODEFAULTLIB:libcmt.lib Here is the example of nmake calling makefile.Ĭl /o myTest.exe main.obj foo.obj /link \ Without a target nmake will look for the first available target in the makefile and build it. We can run nmake without a target or we can specify a target such as nmake clean. While it may look like cl.exe is doing all the work, cl.exe does the compilingįor all the compile options we can use cl and for all the linker options we can use link. When we run nmake, it looks for makefile in the current directory. This nmake section assumes that we have Visual C++ 2008.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |