将标题包括在makefile中
Include headers in MakeFile
我试图将我的标题文件包括在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
您不得将标题添加到SOURCE
变量:所有不是.cpp
文件的元素都直接插入将被清洁的TARGET
。
如果标题名称对应于您可以使用的源名称:
# To obtain object files
%.o: %.cpp %.h
$(CC) -c $(CC_FLAGS) $< -o $@
但是,您会错过通用标头文件。最好的方法是按照Keithsmith的建议使用自动辩论。
相关文章:
- 从矢量<无符号字符>转换为字符* 包括垃圾数据
- Windows 10-使用gtkmm-3.0库和g++[包括再现]的分段故障
- 为什么 cmake 许可证<>样式不包括?
- 计算平均值,不包括上次得分
- 从多个源构造一个对象,包括一个对象向量
- 针对遗留库的链接:来自预制makefile的-lgfortranbegin
- 使用 Makefile 中的头文件编译 Pybind (不使用 cmake)
- 在编译中包括 Botan 2
- 如何在使用Makefile构建后在cmd中运行该程序?
- 将值从另一个数组写入数组,不包括不需要的值 C++
- VS Code C++:不准确的系统包括路径错误(wchar.h,boost/lambda/lambda.hpp)
- Makefile g++ 使用命令行中的 -D 变量进行编译,默认值
- 包括C++头文件
- CPP 包括 Azure DevOps 中的目录设置
- 生成生成 makefile 时不包括 cmake C++11 标志
- 如何将He c mysql库中包括在configure和makefile.am中
- 调整Makefile以包括SDL2
- 将标题包括在makefile中
- 在makefile中包括valgrind
- 编译c++, Makefile基础知识:变量,包括库