A general makefile template I use

Source: Internet
Author: User

For more information, see:

My project has the following directory structures:

dirls/├── include│   └── apue.h├── lib│   ├── error.c│   ├── error.o│   └── Makefile├── src│   ├── dirls.c│   ├── dirls.out│   └── Makefile└── test_client

My makefile template code is as follows:

SRCS = $ (wildcard *. C ../lib/*. c) # wildcard expands all files with the specified directory./And./lib suffixed with C. Objs = $ (SRCS :. C =. o) # objs will be under $ (SRCS. c file. o file cc = GCC # indicates the used compiler des =-I .. /include \ # header file search path-I. libs =-l .. /Lib \ # Link Library search address ccflags =-g-wall-O0 # additional parameter output = dirls. out # Name of the output program all: $ (output): $ (objs) $ (CC) $ ^-O [email protected] $ (DES) $ (libs) %. o: %. C $ (CC)-C $ <$ (ccflags) Clean: Rm-RF *. out *. O # clear intermediate files and generate files. phony: clean

Several makefile templates for other websites are attached:

1. Compile the dynamic library

######################################## ###################### Makefile for shared library. # compile a dynamic link library ################################### ########################## set your own environment optioncc = g ++ cc_flag =-d_nomng -d_fileline # Set Your INC and libinc = Lib =-lpthread-L. /-lsvrtool # Make target lib and relevant obj prg = libsvrtool. soobj = log. O # All targetall: $ (PRG): $ (OBJ) $ (CC)-shared-O [email protected] $ (OBJ) $ (LIB ). suffixes :. c. o. CPP. CPP. o: $ (CC) $ (cc_flag) $ (INC)-C $ *. CPP-o $ *. o. prony: cleanclean: @ echo "Removing linked and compiled files ......; rm-F $ (OBJ) $ (PRG)

2. Compile the static library

######################################## ###################### Makefile for static library. # compile a static Link Library ################################### ########################## set your own environment optioncc = g ++ cc_flag =-d_nomng -d_fileline # static library use 'ar 'command AR = ar # Set Your INC and libinc = Lib =-lpthread-L. /-lsvrtool # Make target lib and relevant obj prg = libsvrtool. aobj = log. O # All targe Tall: $ (PRG): $ (OBJ) $ {ar} RV $ {PRG} $ ?. Suffixes :. c. o. CPP. CPP. o: $ (CC) $ (cc_flag) $ (INC)-C $ *. CPP-o $ *. o. prony: cleanclean: @ echo "Removing linked and compiled files ...... "RM-F $ (OBJ) $ (PRG)

3. executable program

############################################Makefile for simple programs###########################################INC=LIB= -lpthreadCC=CCCC_FLAG=-WallPRG=threadpooltestOBJ=CThreadManage.o CThreadPool.o CThread.o CWorkerThread.o threadpooltest.o$(PRG):$(OBJ)    $(CC) $(INC) $(LIB) -o [email protected] $(OBJ)    .SUFFIXES: .c .o .cpp.cpp.o:    $(CC) $(CC_FLAG) $(INC) -c $*.cpp -o $*.o.PRONY:cleanclean:    @echo "Removing linked and compiled files......"    rm -f $(OBJ) $(PRG)

 

A general makefile template I use

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.