【问题标题】:Compilation error in Makefile, includes not showing upMakefile 中的编译错误,包括未显示
【发布时间】:2010-10-14 17:06:17
【问题描述】:

我有一个makefile如下:

CC = gcc
CFLAGS = -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" $(INCLUDES)
ifdef DEBUG
CFLAGS += -g3
endif

INCLUDES = \
-I../config.include \
-I../log.include \
-I../services.include

SRC_DIR = src
BIN_DIR = bin
BINARY  = report

SRCS = $(shell ls $(SRC_DIR)/*.cpp)
OBJS = $(SRCS:%.cpp=%.o)

all: $(OBJS)
    @mkdir -p $(BIN_DIR)
    $(CC) $(OBJS) -o $(BIN_DIR)/$(BINARY)

clean:
    rm -rf $(BIN_DIR) $(OBJS)

但是,当我运行 make 时,我得到了错误:

g++     -c -o src/report.o src/report.cpp
src/report.cpp:40:20: error: log.h: No such file or directory
src/report.cpp:41:28: error: services.h: No such file or directory
src/report.cpp:41:28: error: config.h: No such file or directory

我知道头文件在那里,并且它们被正确包含。路径也是正确的。 makefile 有问题,但我不知道是什么问题。

请注意,即使我设置 CC = gcc,输出始终是 g++。这不是一个错字,它实际上是我得到的输出 - 再次,不知道为什么。

救命!

【问题讨论】:

    标签: c++ gcc makefile g++ compilation


    【解决方案1】:

    对于 .cpp 文件,您必须重新定义 CXXFLAGSCXX 而不是 CFLAGSCC

    检查make -p的输出并搜索%.o: %.cpp规则。

    【讨论】:

    • 谢谢!我对 Makefile 没有太多经验,但这应该是一个提示。
    【解决方案2】:

    您没有针对单个目标文件 ($(OBJS)) 的目标,因此 Make 搜索其隐式规则列表,其中之一是使用 C++ 编译器从 .cpp 文件生成 .o 文件,该编译器设置为by CXX(默认情况下可能是 g++)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-19
      • 1970-01-01
      • 1970-01-01
      • 2012-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多