简体   繁体   English

通用Makefile忽略变量

[英]Generic Makefile disregarding variables

C++ project with a directory structure and Makefile styled after this blog post a simple c plus plus project structure . C ++项目具有目录结构,并且在此博客中介绍了简单的c plus plus项目结构具有 Makefile样式。 However, in the modified output from running makefile the variables do not seem to carry values through the compilation process. 但是,在运行makefile的修改后的输出中,变量似乎没有在编译过程中携带值。

edited (now working): Makefile 编辑(正在运行):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. 回想起来,“ $(”是该代码中的一对常见符号,可能会因产生“($”的错误而被反转,除了makefile不会通知您这种错误类型。因此,只需在文档中搜索“(( $”会发现错误。

There is a tiny problem in your makefile! 您的makefile中有一个小问题! Substitue this: 替换为:

OBJECTS := $(patsubst ($SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))

With this: 有了这个:

OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM