簡體   English   中英

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.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 $@ $<

編輯:-----------------------------------------

通過評論解決:

添加此行修復它:.PRECIOUS $(compileDir)%。o

你可以補充一下

.PRECIOUS: %.o

這應該是隱含的,但也許你有一個奇怪的設置。

Make將您的.o文件視為中間文件並將其刪除。 您可以通過添加特殊.SECONDARY目標的依賴項來阻止自動刪除它們。 有關詳細信息,請參閱隱式規則鏈 祝好運!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM