Makefile自动删除.o文件
makefile auto removing .o files
我在大学里修了一门c++课程,他们想让我们手动输入所有的测试文件…但是,我知道有一种方法可以做到这一点,这就是我最终使用当前(http://pastebin.com/6d9UtKM4) makefile的原因。我的问题是,为什么这个makefile自动删除它用于编译时使用的所有.o文件?我不会死,但我想保留。o文件。我在这里粘贴了makefile (http://pastebin.com/6d9UtKM4)。我还在这里粘贴了运行"make tests"的当前结果(http://pastebin.com/h3Ny3dib)。(请注意该页底部自动删除所有.o文件的部分。)
我还希望能够使它像这样生成:
- g++ -o compileDir/assembler。0 -c -Wall src/assembly .cpp
- g++ -o compileDir/string。0 -c -Wall src/string.cpp
- g++ -c -Wall -o compileDir/test_assignment。o testSrc/test_assignment.cpp
- g++ -o testDir/test_assignment compileDir/test_assignment。o compileDir/字符串。o compileDir/assembler.o
- g++ -c -Wall -o compileDir/test_括号。o testSrc/test_bracket.cpp
- g++ -o testDir/test_bracket compileDir/test_bracket。o compileDir/字符串。o compileDir/assembler.o
- testDir/test_bracket
- testDir/test_assignment
换句话说,我希望它先编译所有内容,然后再运行所有内容。我希望这个要求不会太过分!
编辑:附加信息:(这是"进行测试"的代码)
tests: assembler.o string.o $(test_output) $(test_stringOutput)
@echo '--- Testing complete ---'
$(testDir)%: $(compileDir)%.o string.o
g++ -o $@ $< $(compileDir)string.o $(compileDir)assembler.o
$@
@echo ''
$(compileDir)%.o: $(testSourceDir)%.cpp
g++ -c -Wall -o $@ $<
$(compileDir)%.o: $(testStringSrc)%.cpp
g++ -c -Wall -o $@ $<
编辑 : -----------------------------------------
通过注释解析:
添加这一行修复它:.PRECIOUS $ (compileDir) % . o
你可以添加
.PRECIOUS: %.o
应该是隐式的,但也许你有一个奇怪的设置
Make将您的.o
文件视为中间文件并删除它们。您可以通过将它们添加到特殊.SECONDARY
目标的依赖项来防止它们被自动删除。有关更多细节,请参阅隐式规则链。好运!
相关文章:
- 如何在我从C++文件中读取后立即删除行
- 删除 XML 文件中的子节点C++
- 如何在输入新内容 c++ 之前删除文件中的所有内容
- 如何更新和删除文本文件中的特定逗号分隔值?C++
- 为什么我的程序在读取/写入文件时会删除最重要的数字?
- 将内容从第一个文件("constituencies")移动到第二个文件("temp")并在之后重命名时,我的文件被删除
- 文件模式标志"ios::app"是否用于删除文件(如果文件已存在)?
- 如何自动获取我的项目的路径并删除一些文件
- C++ VS 错误:<实验/文件系统>提供 std::experimental::文件系统的标头已被Microsoft弃用,将被删除
- 如果我删除指针,我的C++程序会意外删除系统文件吗?
- 在 c++ 中打开文件、删除标点符号并追加到另一个文件中
- 文件删除(使用取消链接)与释放所有磁盘空间之间的延迟
- 重命名批处理文件(删除名称中的一些符号)(python/matlab/shell)
- 如何找到字符串并使用C 文件中的文件删除它
- 使用 DEF 文件删除 dll 导出的名称
- 关闭后等待文件删除
- c++中的文件删除
- 如何共享文件删除权限时,我打开一个文件ifstream
- 典型的Win32文件删除(IDropTarget::drop)实现
- 生成文件模式规则:循环生成文件.o < - 删除生成文件依赖项