Makefile: Compiling from directory to another directory

后端 未结 1 1109
借酒劲吻你
借酒劲吻你 2020-12-14 23:25

I am trying to use Makefile to compile a bunch of .cpp files located in src/code/*.cpp, then compile each *.o in build/,

1条回答
  •  执笔经年
    2020-12-15 00:20

    Your patsubst function is wrong; you can't use shell wildcard characters like *. You want:

    OBJECTS = $(patsubst $(SOURCEDIR)/%.cpp,$(BUILDDIR)/%.o,$(SOURCES))
    

    Also you should be using SOURCEDIR and BUILDDIR everywhere, not just in some places (otherwise you'll get inconsistencies). And finally, your SOURCEDIR value is wrong: it should not start with / I expect:

    SOURCEDIR = src/code
    
    SOURCES = $(wildcard $(SOURCEDIR)/*.cpp)
    

    0 讨论(0)
提交回复
热议问题