############################################Makefile for simple programs###########################################Inc=LIB=-LPTHREADCC=Gcccxx=g++LINK=g++#-fpermissive: Means compatibility with old grammarc_flags=-g-wall-fpermissive-std=C11cxx_flags=-g-wall-fpermissive-std=c++11Inc_path=-I./-I./kenlm-i./kiss_fft130-i./iniparser2/Srclib_path=-l./Ext_lib=-wl,-rpath,./-ltensorflow-lkenlm-lkenlm_util-lkenlm_builder-lkenlm_filter-lkenlm_interpolate-lbz2-lz-llzma-PTHREADPRG=Testsrcs=$ (Wildcard *. C) SRCs+=$ (Wildcard *. cpp) C_objs=$ (Patsubst%.c,%.o,$ (wildcard *. C)) Cxx_objs=$ (Patsubst%.cpp,%.o,$ (wildcard *. cpp)) all:$ (PRG)#library files are required when linking$ (PRG): $ (CXX_OBJS) $ (C_OBJS) $ (LINK) $^ $ (lib_path) $ (ext_lib)-o [email protected]#need a header file when compiling%.o:%. cpp $ (CXX) $ (cxx_flags)-C $< $ (inc_path)-o [email protected]%.o:%. C $ (CC) $ (c_flags)-C $< $ (inc_path)-o [email protected]. Prony:cleanclean: @echo"removing linked and compiled files ..."RM-RF $ (PRG) $ (CXX_OBJS) $ (C_OBJS)
-I (uppercase i), add the Include path -I use at compile time, tell the compiler to go to which path to find files such as:-i/home/hello/include means that will /home/hello/ The Include directory is the first directory to look for a header file. The compiler's search order is:/home/hello/include-->/usr/include-->/usr/local/include.
If you have a file hello.h in/home/hello/include, you can refer to the file using #include
-L (lowercase l), add Reference link library -l use it when linking, it is to tell the linker, which library to use. such as:-Lpthread tells the linker (linker), the program needs to link pthread This library, where the pthread is the library name is not a file name, specifically, the file sentence is libpthread.so.
-L, add the link library path -L followed the path to tell the linker where to find the library (. so file or. a file), which is only used when linking. such as:-l/home/hello/lib means the /home/hello/lib directory as the first directory to find the library file, the search order is:/home/hello/lib-->/usr/lib-->/ usr/local/Lib. You can add multiple include paths, and the linker's search order is added in order.
-Wl,rpath, add run-time library path -Wl,rpath followed by path, run time with. This compile instruction is logged to the target file at compile time, so the compiled target file will be executed with the path given here to find the library file. such as:-wl,rpath=/home/hello/lib means the /home/hello/lib directory as the first directory to look for library files when the program is run, the program search order is:/home/hello/lib-->/ usr/lib-->/usr/local/Lib. You can add multiple include paths, and the order in which programs are searched at run time is the order in which they are added.
-L is the compilation path,-wl,rpath is the run path, in the configuration of the project in order to standardize, compiled by the target (. So or executable file)
Not necessarily with the source file (Main.cpp,xx.cpp) in a folder. If not in a folder, at compile time, the-L is followed by the relative
The path to the source file, followed by the path of the-wl,rpath relative to the target (. So or executable), is exactly relative to the work
The path to the directory. Different ides are sometimes slightly different in configuration and need to be noted.
Linux Makefile Simple Template