guides:software:make:start
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
guides:software:make:start [2020/07/20 17:23] – [Makefiles for Multiple File Compilation] wikiadmin | guides:software:make:start [2024/07/25 15:01] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 3: | Line 3: | ||
Make is a build automation tool that is designed to automatically construct executable programs from source code. | Make is a build automation tool that is designed to automatically construct executable programs from source code. | ||
+ | |||
+ | Make simplifies the build process for projects at all levels. | ||
===== Simple Use ===== | ===== Simple Use ===== | ||
Line 291: | Line 293: | ||
One of the most powerful uses of make is to compile multiple files into a single executable. | One of the most powerful uses of make is to compile multiple files into a single executable. | ||
+ | |||
+ | ==== Example ==== | ||
For this example the code is decomposed into the following files: | For this example the code is decomposed into the following files: | ||
Line 354: | Line 358: | ||
</ | </ | ||
* // | * // | ||
- | * <code c++ | + | * <code c++> |
#include < | #include < | ||
Line 379: | Line 383: | ||
OBJS = hello | OBJS = hello | ||
- | .PHONY: all | ||
all: ${OBJS} | all: ${OBJS} | ||
Line 388: | Line 391: | ||
stringTools.o: | stringTools.o: | ||
- | .PHONY: clean | ||
clean: | clean: | ||
rm -f ${OBJS} *.o | rm -f ${OBJS} *.o | ||
</ | </ | ||
+ | |||
+ | To build this code, you are required to compile stringTools.cpp into stringTools.o, | ||
+ | |||
+ | This could be accomplished by hand by executing the following | ||
+ | < | ||
+ | g++ -c greeting.cpp | ||
+ | g++ -c stringTools.cpp | ||
+ | g++ -o hello hello.cpp stringTools.o greeting.o | ||
+ | </ | ||
+ | |||
+ | Of course, if you have command line flags, this becomes much more complex. | ||
+ | |||
+ | Using the above // | ||
+ | |||
+ | < | ||
+ | $ make | ||
+ | g++ -g -O3 -Wpedantic -Wall -Wextra -Wmisleading-indentation -Wunused -Wuninitialized -Wshadow -Wconversion -std=c++14 | ||
+ | g++ -g -O3 -Wpedantic -Wall -Wextra -Wmisleading-indentation -Wunused -Wuninitialized -Wshadow -Wconversion -std=c++14 | ||
+ | g++ -g -O3 -Wpedantic -Wall -Wextra -Wmisleading-indentation -Wunused -Wuninitialized -Wshadow -Wconversion -std=c++14 | ||
+ | $ ls | ||
+ | Makefile | ||
+ | greeting.cpp | ||
+ | </ | ||
+ | |||
+ | Note that all components are compiled and the final executable is produced. | ||
+ | |||
+ | < | ||
+ | $ touch greeting.cpp | ||
+ | $ make | ||
+ | g++ -g -O3 -Wpedantic -Wall -Wextra -Wmisleading-indentation -Wunused -Wuninitialized -Wshadow -Wconversion -std=c++14 | ||
+ | g++ -g -O3 -Wpedantic -Wall -Wextra -Wmisleading-indentation -Wunused -Wuninitialized -Wshadow -Wconversion -std=c++14 | ||
+ | </ | ||
+ | |||
+ | ==== The Makefile ==== | ||
+ | |||
+ | In order to build this project using make, you need to inform make of the dependencies built into the project. | ||
+ | |||
+ | <code make> | ||
+ | hello: | ||
+ | </ | ||
+ | |||
+ | You do not need to tell make that //hello// depends on // | ||
+ | |||
+ | You also do not need to tell make that //hello// depends on // | ||
+ | |||
+ | <code make> | ||
+ | stringTools.o: | ||
+ | </ | ||
+ | |||
+ | This line tells make that // | ||
+ | |||
+ | <code make> | ||
+ | greeting.o: greeting.h stringTools.h | ||
+ | </ | ||
+ | |||
+ | This line tells make that // | ||
+ |
guides/software/make/start.1595265807.txt.gz · Last modified: 2024/07/25 15:01 (external edit)