0

基本上我在 Windows 中有简单的 makefile。我读过这个线程。他们说如果我在 makefile 的同一文件夹中有一个名为 exampleclean的文件,并且我有一个用于清理 makefile 中某些文件的命令并且它的名称是 clean,那么 makefile 将不会运行该命令。而是显示此消息

'clean' is up-to-date

现在为了解决这个问题,我应该添加.PHONY : clean,因此,即使我在同一个文件夹中有另一个名为 的文件clean,makefile 也会运行实际的命令。这是我的理解。添加phony绝对没有任何效果。它再次打印出此消息。

'clean' is up-to-date

这是我在 Windows 中的生成文件。注意:我使用nmake

# Specify compiler 
CC = cl.exe

# Specify flags
# /Zi -- Enable debugging    
# /O2 -- 
CFLAGS = /EHsc /c /W1 /Zi /O2

# Specify linker
LINK = link.exe

.PHONY : all
all : app

# Link the object files into a binary
app : main.o
    $(LINK) /OUT:app.exe main.o 

# Compile the source files into object files 
main.o : main.cpp
    $(CC) $(CFLAGS) main.cpp /Fomain.o 

# Clean target
.PHONY : clean
clean:
    del *.o *.exe *.pdb

主文件

#include <iostream>

int main()
{
    std::cout << "Hello World!" << std::endl;
    return 0;
}

同一文件夹中的文件。

在此处输入图像描述

4

0 回答 0