【发布时间】:2014-01-27 01:01:09
【问题描述】:
我正在尝试将我的头文件包含在 makefile 中,这样每次我编辑没有相应 cpp 文件的头文件时,我都不必make clean && make。
编辑
到目前为止,我有这个:
# Declaration of variables
CC = g++
CC_FLAGS = -Wall -g
# File names
EXEC = Main
DEPS = MoveLogic.hpp
SOURCES = $(wildcard *.cpp) $(wildcard Pieces/*.cpp)
TARGET = $(SOURCES:.cpp=.o)
TARGET_DEPS = $(DEPS:.hpp=.o)
# Main target
$(EXEC): $(TARGET) $(TARGET_DEPS)
$(CC) $(TARGET) $(TARGET_DEPS) -o $(EXEC)
# To obtain dependanies
%.o: %.hpp
$(CC) $(DEPS) -o $@
# To obtain object files
%.o: %.cpp
$(CC) -c $(CC_FLAGS) $< -o $@
# To remove generated files
clean:
rm -f $(EXEC) $(TEST) $(TARGET)
但我得到了错误
ignoring file MoveLogic.o, file was built for unsupported file format ( 0x43 0x50 0x43 0x48 0x01 0x0C 0x00 0x00 0x27 0x08 0x00 0x00 0x0B 0x02 0x68 0x42 ) which is not the architecture being linked (x86_64): MoveLogic.o
【问题讨论】:
-
您正在寻找的是依赖生成。 GCC -MM 或 -MT 开关是您解决方案的开始。寻找相关的 SO 问题。 makefile dependency
-
@KeithSmith 我还是很困惑
-
您是如何使用
DEPS变量的? -
@Matthias 到目前为止,我将其添加到
SOURCES = ... $(DEPS)......但我得到了clang: error: cannot specify -o when generating multiple output files所以我没有更多 -
我通常手动放置依赖项以便只编译需要的内容(但这是一个可维护性混乱):
foo.cpp: foo.h bar.h baz.h
标签: c++ makefile header-files