First create the Bin,src,lib under the project folder, as well as include folders, create Lib or lib64 folder outside the project folder, put the file type into several folders under the project folder, respectively. Then according to the actual needs of the following Makefile1 for the actual needs of the rewrite, will eventually be generated under SRC *.o and other obj files, and in the project folder outside the Lib or lib64 to generate the required static library files. This does not generate an. exe executable file
workroot=. /..Libname=Flumelogbin_dir=Binsrc_dir=Srclib_dir=LibINCLUDE=-i./include-i/usr/local/include-I.. /lib64/thrift/include-I.. /cfg/includeInstall_path=$ (workroot)/Flumeloglib= .. /lib64/thrift/lib/libthrift.a. /CFG/LIB/LIBCFG.A-Static-lpthreadsources= $ (wildcard $ (src_dir)/*. cpp) OBJS = $ (patsubst%.cpp,%.o,$ (SOURCES)) Common_defines =-dlinux-d_reenterant-d_largefile_source-d_file_offset_ Bits=64 defines=$ (common_defines) #CXXFLAGS =-fpic-g-wall-w $ (defines) $ (INCLUDE) cxxflags=-g-wall-w $ (defines) $ (INC Lude) CXX = g++ AR = ar#=========================================================================output_lib=lib$ ( libname). abit:=$ (Shell getconf long_bit) ifeq (${bit}, +) output_path=. /lib64/$ (libname) Else output_path=: /lib/$ (libname) endif#-----------------------------------------------------------------# # make all#-------------- ---------------------------------------------------#all: Clean outputdiroutputdir:output if [!-D $ (output_path)]; Then mkdir $ (output_path); fi if [!-D $ (output_path)/lib]; Then mkdir $ (output_path)/lib; fi if [!-D $ (output_path)/include]; Then mkdir $ (output_path)/include; Fi cp lib/$ (output_lib) $ (output_path)/lib CP include/*.h $ (output_path)/include#----------------------------------- ------------------------------# # make library#-----------------------------------------------------------------# Output: $ (OBJS) if [!-D $ (lib_dir)]; Then mkdir $ (lib_dir); Fi Ar-ruv $ (lib_dir)/$ (output_lib) $ (OBJS) $ (OBJS):%.O:%.cpp $ (CXX)-C $<-O [email protected] $ (INCLUDE) $ (LIB) $ (cxxflags) #-----------------------------------------------------------------# # Make clean#--------------- --------------------------------------------------#clean: Rm-f $ (OBJS) $ (lib_dir)/*.a#--------------------------- --------------------------------------# # Make install#---------------------------------------------------------- -------#install: OutputDir if [!-D $ (install_path)]; Then Mkdir-p $ (install_path); Fi CP-RF $ (output_path)/* $ (Install_path)
Here is Makefile2, using the previously generated libflumelog.a and the libraries you depend on, you can generate the final EXE file, which is also suitable for applying
Test:test. cpp g + +-g-o Test-dhave_netinet_in_h Test. cpp -i/usr/locl/ -I.. /.. /cfg/include -I.. /.. /lib64/thrift/include -I.. /.. /lib64/flumelog/include / -wl,--start- group .. /.. /lib64/flumelog/lib/libflumelog. a .. /.. /lib64/thrift/lib/libthrift. a .. /.. /cfg/lib/libcfg. a -end -group
。
Makefile Small Template