minimum c++ make file for linux

后端 未结 11 1794
眼角桃花
眼角桃花 2020-12-23 17:32

I\'ve looking to find a simple recommended \"minimal\" c++ makefile for linux which will use g++ to compile and link a single file and h file. Ideally the make file will not

相关标签:
11条回答
  • 2020-12-23 18:13

    Have you looked at OMake ?

    OMakeroot

    open build/C
    DefineCommandVars()
    .SUBDIRS: .
    

    OMakefile

    .DEFAULT: $(CXXProgram test, test)
    

    Then on Linux or Windows, simply type:

    omake
    

    As a bonus, you automatically get:

    • parallel builds with the -j option (same as make).
    • MD5 checksums instead of timestamps (build becomes resilient to time synchronization failures).
    • Automatic and accurate C/C++ header dependencies.
    • Accurate inter-directory dependencies (something that recursive make does not offer).
    • Portability (1 build chain to rule them all, immune to path style issues).
    • A real programming language (better than GNU make).
    0 讨论(0)
  • 2020-12-23 18:14

    Have you looked at SCons?

    Simply create a SConstruct file with the following:

    Program("t.cpp")
    

    Then type:

    scons
    

    Done!

    0 讨论(0)
  • 2020-12-23 18:14

    a fairly small GNU Makefile, using predefined rules and auto-deps:

    CC=c++
    CXXFLAGS=-g -Wall -Wextra -MMD
    LDLIBS=-lm
    program: program.o sub.o
    clean:
        $(RM) *.o *.d program
    -include $(wildcard *.d)
    
    0 讨论(0)
  • 2020-12-23 18:16

    If your issues are because autoconf thinks the .h file is a c file, try renaming it to .hpp or .h++

    0 讨论(0)
  • 2020-12-23 18:17

    I was hunting around for what a minimal Makefile might look like other than

    some_stuff:
        @echo "Hello World"
    

    I know I am late for this party, but I thought I would toss my hat into the ring as well. The following is my one directory project Makefile I have used for years. With a little modification it scales to use multiple directories (e.g. src, obj, bin, header, test, etc). Assumes all headers and source files are in the current directory. And, have to give the project a name which is used for the output binary name.

    NAME = my_project
    
    FILES = $(shell basename -a $$(ls *.cpp) | sed 's/\.cpp//g')
    SRC = $(patsubst %, %.cpp, $(FILES))
    OBJ = $(patsubst %, %.o, $(FILES))
    HDR = $(patsubst %, -include %.h, $(FILES))
    CXX = g++ -Wall
    
    %.o : %.cpp
            $(CXX) $(HDR) -c -o $@ $<
    
    build: $(OBJ)
            $(CXX) -o $(NAME) $(OBJ)
    
    clean:
            rm -vf $(NAME) $(OBJ)
    
    0 讨论(0)
提交回复
热议问题