【发布时间】:2011-11-06 00:22:51
【问题描述】:
我正在大学学习 C++ 课程,他们希望我们手动输入所有测试文件...但是我知道,有一种方法可以做到这一点,这就是我最终的结果current(http://pastebin.com/6d9UtKM4) 生成文件。我的问题是,为什么这个 makefile 会在完成后自动删除它用于编译的所有 .o 文件?它不会杀死我,但我想保留 .o 文件。我已经粘贴了makefile here(http://pastebin.com/6d9UtKM4)。我还粘贴了运行“make tests”here(http://pastebin.com/h3Ny3dib) 的当前结果。 (请注意该页面底部自动删除所有 .o 文件的部分。)
我也希望能够使它像这样生成:
- g++ -o compileDir/assembler.o -c -Wall src/assembler.cpp
- g++ -o compileDir/string.o -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/string.o compileDir/assembler.o
- g++ -c -Wall -o compileDir/test_bracket.o testSrc/test_bracket.cpp
- g++ -o testDir/test_bracket compileDir/test_bracket.o compileDir/string.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 $@ $<
编辑:-----------------------------------------
通过 cmets 解决:
添加此行修复它: .PRECIOUS $(compileDir)%.o
【问题讨论】:
-
你不是每次都在运行
make clean,是吗? -
不,我只是在运行 make 测试。那里的最终链接的输出 (pastebin.com/h3Ny3dib) 是键入 make tests 的结果