MakefilesHowto - variable on the command line Approach 2 Of...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Makefiles are easy. Approach 1: In fact, to build a simple program that doesn't depend on any libraries, you don't even need a makefile. make(1) is smart enough to figure it all out itself. For instance, if you have a file "xzq0001_hw1.cpp" (Note: xzq0001 is my Auburn ID) in the current directory: $ ls xzq001_hw1.cpp $ make xzq0001_hw1 g++ xzq0001_hw1 -o xzq0001_hw1 make(1) will detect the type of file and compile it for you, automatically naming the executable the same as the input file (g++(1)) xzq0001_hw1.cpp will give you a file called a.out unless you manually specify a name for it). If you need libraries, you can specify them by setting the LDFLAGS
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: variable on the command line. Approach 2: Of course, you also can prepare a simple makefile (available at: http://www.eng.auburn.edu/~xqin/courses/comp2710/makefile ) as follows: xzq0001_hw1: xzq0001_hw1.cpp g++ xzq0001_hw1.cpp -o xzq0001_hw1 clean: rm -f *.o xzq0001_hw1 where xzq_0001 is my auburn ID. Suppose you have two files "xzq0001_hw1.cpp" and “makefile” in the current directory, then you will have: $ ls makefile xzq001_hw1.cpp $ make g++ xzq0001_hw1 -o xzq0001_hw1 make is smart enough to use the first rule in the Makefile as the default action, so: $ ls Makefile xzq0001_hw1 xzq0001_hw1.o References: http://wlug.org.nz/MakefileHowto...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online