C, C + + mixed programming General makefile template __linux

Source: Internet
Author: User

First Template: All. C,. cpp, *.h files are in the same directory, not layered.

###################################### # ###################################### #source File Source: = $ (wildcard *.c) $ (wildcard *.cpp) OBJS: = $ (Patsubst%.c,%.o,$ (Patsubst%.cpp,%.o,$ (SOURCE)) #target You can change test to what Want TARGET: = Host_send #compile and lib parameter CC: = gcc CXX: = g++ LIBS: =-lusb-1.0-luvc-lopencv_ Highgui-lreadline-lopencv_imgcodecs-lopencv_imgproc-lc-lopencv_calib3d-lopencv_core #LIBS: =-LUSB-1.0-LUVC LDF
LAGS: =-l/usr/libx86_64-linux-gnu/-l/usr/lib/x86_64-linux-gnu-l/usr/local/lib-l. Defines: =-fpic-wl,-rpath=. INCLUDE: =-I-i./include-i/usr/include/libusb-1.0-i/usr/local/include cflags: =-g-wall-o3 $ (defines) $ (include) CX Xflags:= $ (cflags) #i you are should do anything here. Phony:everything Objs Clean Veryclean rebuild everything: $ (target) All: $ (target) OBJS: $ (OBJS) rebuild:verycle An everything CLEAN:RM-RF *.o RM $ (target) Veryclean:clean RM-RF $ (target)

$ (TARGET): $ (OBJS) $ (CXX) $ (cxxflags)-O $@ $ (OBJS) $ (ldflags) $ (LIBS) 

The second template:. C and. cpp files in the SRC directory, the file structure is more clear.

Binfile = Test ifdef VERBOSE q = e = @true Else Q = @ E = @echo endif cfiles: = $ (She ll find src-mindepth 1-maxdepth 4-name "*.c") Cxxfiles: = $ (Shell find src-mindepth 1-maxdepth 4-name "*.cpp") infi
LES: = $ (cfiles) $ (cxxfiles) Objfiles: = $ (cxxfiles:src/%.cpp=%) $ (cfiles:src/%.c=%)
Depfiles: = $ (cxxfiles:src/%.cpp=%) $ (cfiles:src/%.c=%)
Ofiles: = $ (OBJFILES:%=OBJ/%.O) Commonflags: =-wall-wextra-pedantic-o3 defines: =-fpic-wl,-rpath=. INCLUDE: =-I-i./include-i/usr/include/libusb-1.0-i/usr/local/include ldflags: =-l/usr/libx86_64-linux-gnu/-L/usr  /lib/x86_64-linux-gnu-l/usr/local/lib-l. LIBS: =-lusb-1.0-lopencv_core-lopencv_highgui-lreadline-lopencv_calib3d -lopencv_imgcodecs-lc-lopencv_imgproc ifdef DEBUG Commonflags: = $ (commonflags)-G endif cflags: = $ (Commonfla GS)--std=c99 $ (defines) $ (include) Cxxflags: = $ (commonflags)--std=c++0x $ (defines) $ (include) Depdir: = Deps All: $ (BI NFILE) ifeq ($ (MAKECmdgoals),-include MAKEFILE.DEP endif ifneq ($ (filter-out clean, $ (makecmdgoals)),)-include makefile.dep endif CC = gcc CXX = g++-include makefile.local. Phony:clean all depend. SUFFIXES:OBJ/%.O:SRC/%.C $ (E) c-compiling $< $ (Q) if [!-d ' dirname $@ ']; Then Mkdir-p ' dirname $@ ';  Fi $ (q) $ (CC)-O $@-C $< $ (cflags) Obj/%.o:src/%.cpp $ (E) c++-compiling $< $ (q) If [!-d ' dirname $@ ']; Then Mkdir-p ' dirname $@ '; Fi $ (q) $ (CXX)-O $@-C $< $ (cxxflags) MAKEFILE.DEP: $ (cfiles) $ (cxxfiles) $ (E) Depend $ (q) for I $ (^); Do $ (CXX) $ (cxxflags)-mm "$${i}"-mt obj/' basename $${i%.*} '. O; Done > $@ $ (binfile): $ (ofiles) $ (e) Linking $@ $ (Q) $ (CXX)-O $@ $ (ofiles) $ (ldflags) $ (LIBS) Clean: $ (e) R
 emoving files $ (Q) Rm-f $ (binfile) obj/* MAKEFILE.DEP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.