C++ project with a directory structure and Makefile styled after this blog post a simple c plus plus project structure . However, in the modified output from running makefile the variables do not seem to carry values through the compilation process.
edited (now working): Makefile
HOST_COMPILER := g++
SRCDIR := src
BUILDDIR := build
TARGET := bin/runner
SRCEXT := cc
SOURCES := $(shell find $(SRCDIR) -type f -name "*.$(SRCEXT)")
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
# internal flags
CXXFLAGS := -std=c++11 -Wall -g -fopenmp
MAGICKFLAGS := `Magick++-config --cxxflags --cppflags --ldflags --libs`
INCLUDES := -I/usr/include/ImageMagick-6
LIBRARIES := -L/usr/local/lib/ -lMagick++-6.Q16 -lMagick++
$(TARGET) : $(OBJECTS)
$(HOST_COMPILER) $^ -o $(TARGET) $(LIBRARIES)
$(BUILDDIR)/%.o : $(SRCDIR)/%.$(SRCEXT)
@mkdir -p $(BUILDDIR)
$(HOST_COMPILER) $(CXXFLAGS) $(MAGICKFLAGS) $(INCLUDES) -c -o $@ $<
clean:
rm -r $(BUILDDIR) $(TARGET)
In retrospect "$(" is a common pair of symbols in this code which could be reversed for the error producing "($", except makefile doesn't inform you of such a misstype. So just a search on the document for "($" would have found the error.
There is a tiny problem in your makefile! Substitue this:
OBJECTS := $(patsubst ($SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
With this:
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.