Welcome to follow my public account [Jizhi Vision], reply 001 to get Google programming specification

O_o >_< O_o O_o ~_~ O_o

This tutorial details how to quickly build a single project using a Makefile under Linux.

The highlight of this article is the quick build project, so I won’t go into Makefile syntax at length.

To get started, let’s say you have a test CPP: test.cpp, and then it might have some dependencies, such as OpencV, CUDA, etc. Now give a Makefile that can be easily configured to compile your test executable for quick test validation.

## MakefileCXX = g++ CXX_FLAGS += -std=c++14 CXX_FLAGS += -Wl,-rpath-link INCLUDES += -I.. / XXXX /include # header path INCLUDES += -i.. /xxx/xxx/include LINKS += -L.. / XXX /lib # library path += -l.. LIBS += -lopencv_imgproc -lopencv_imgcodecs -lopencv_core LIBS += -lopencv_imgproc -lopencv_imgcodecs -lopencv_core -lopencv_dnn

# For debug build, use the command: `make debug=1'Ifeq ($(debug), 1) # debug CXX_FLAGS += -ddebug -g endif SRCS = test.cc EXECUTABLE = test
$EXECUTABLE: $(SRCS) #
	$(CXX) $(SRCS) $(CXX_FLAGS) $(INCLUDES) $(LINKS) $(LIBS) -o $(EXECUTABLE)

clean:                                                                 # make clean
	rm -f $(EXECUTABLE)
Copy the code

Put two files in the same directory:

- Makefile
- test.cpp
Copy the code

Execute compilation:

make
Copy the code

If you need debug, you can compile it like this:

make debug=1
Copy the code

This will generate the test executable, which is very fast and simple.


I’ve shared a quick way to build a single project using a Makefile in Linux. I hope this will help you a little.


How to build a single project using Makefile in Linux