Linux: several common makefile templates

Source: Internet
Author: User

No, summarize the personal commonly used makefile template for later use.

1. Compiling the dynamic library

[Plain]View PlainCopy
  1. #############################################################
  2. # Makefile for Shared library.
  3. # Compile the dynamic link library
  4. #############################################################
  5. #set Your own environment option
  6. CC = g++
  7. Cc_flag =-d_nomng-d_fileline
  8. #set Your Inc and Lib
  9. INC =
  10. LIB =-lpthread-l./-lsvrtool
  11. #make target Lib and relevant obj
  12. PRG = libsvrtool.so
  13. OBJ = LOG.O
  14. #all Target
  15. all:$ (PRG)
  16. $ (PRG): $ (OBJ)
  17. $ (CC)-shared-o [email protected] $ (OBJ) $ (LIB)
  18. . Suffixes:. C. o CPP
  19. . CPP.O:
  20. $ (CC) $ (cc_flag) $ (INC)-C $*.cpp-o $*.O
  21. . Prony:clean
  22. Clean
  23. @echo "Removing linked and compiled files ...;
  24. Rm-f $ (OBJ) $ (PRG)

2. Compile the static library

[Plain]View PlainCopy
  1. #############################################################
  2. # Makefile for Static library.
  3. # Compile a static link library
  4. #############################################################
  5. #set Your own environment option
  6. CC = g++
  7. Cc_flag =-d_nomng-d_fileline
  8. #static library use ' ar ' command
  9. AR = AR
  10. #set Your Inc and Lib
  11. INC =
  12. LIB =-lpthread-l./-lsvrtool
  13. #make target Lib and relevant obj
  14. PRG = LIBSVRTOOL.A
  15. OBJ = LOG.O
  16. #all Target
  17. all:$ (PRG)
  18. $ (PRG): $ (OBJ)
  19. ${ar} RV ${prg} $?
  20. . Suffixes:. C. o CPP
  21. . CPP.O:
  22. $ (CC) $ (cc_flag) $ (INC)-C $*.cpp-o $*.O
  23. . Prony:clean
  24. Clean
  25. @echo "Removing linked and compiled files ..."
  26. Rm-f $ (OBJ) $ (PRG)

3. Executable program

[Plain]View PlainCopy
  1. ###########################################
  2. #Makefile for simple programs
  3. ###########################################
  4. Inc=
  5. lib=-lpthread
  6. Cc=cc
  7. Cc_flag=-wall
  8. Prg=threadpooltest
  9. OBJ=CTHREADMANAGE.O CTHREADPOOL.O CTHREAD.O CWORKERTHREAD.O THREADPOOLTEST.O
  10. $ (PRG): $ (OBJ)
  11. $ (CC) $ (INC) $ (LIB)-o [email protected] $ (OBJ)
  12. . Suffixes:. C. o CPP
  13. . CPP.O:
  14. $ (CC) $ (cc_flag) $ (INC)-C $*.cpp-o $*.O
  15. . Prony:clean
  16. Clean
  17. @echo "Removing linked and compiled files ..."
  18. Rm-f $ (OBJ) $ (PRG)


Random combination, extrapolate will write the makefile for the project

Linux: several common makefile templates

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.