简体   繁体   English

GNU无法检测Windows上的文件是否已更改

[英]GNU make not detecting if files are changed on windows

I'm a noob with make in general so apologies in advance. 我是个菜鸟,因此通常会提前道歉。

I have a folder structure, where foo.cpp is in the root of the project and all other .cpp files are in one and all headers in another folder. 我有一个文件夹结构,其中foo.cpp位于项目的根目录中,所有其他.cpp文件位于一个文件夹中,所有标头位于另一个文件夹中。 Whenever I change something make just says that everything is up to date. 每当我更改某些内容时,只需说所有内容都是最新的即可。

Working on windows 10. 在Windows上工作10。

The code is from 该代码来自

my makefile: 我的makefile文件:

OBJS = foo.o bar.o
CC = g++
INCLUDE_PATHS = -IC:\Mingw_libs\include\SDL2
LIBRARY_PATHS = -LC:\Mingw_libs\lib -Iheaders
COMPILER_FLAGS = -std=c++11
LINKER_FLAGS = -lmingw32 -lSDL2main -lSDL2 -lSDL2_image 

OUTPUTFILE = main

all: $(OBJS)
    $(CC) $(OBJS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(LINKER_FLAGS) -o $(OUTPUTFILE)

clean:
    rm *.o
    rm *.exe

foo.o:
    $(CC) -c foo.cpp $(INCLUDE_PATHS) $(COMPILER_FLAGS) $(LIBRARY_PATHS) $(LINKER_FLAGS)

bar.o:
    $(CC) -c sources/bar.cpp $(INCLUDE_PATHS) $(COMPILER_FLAGS) $(LIBRARY_PATHS) $(LINKER_FLAGS)

You should declare target dependencies like that: 您应该像这样声明目标依赖关系:

foo.obj: foo.c
    ....

Otherwise make will not now wich files to check for changes. 否则,make现在不会将文件夹在中间以检查更改。

Your makefile has no dependencies for foo.o or bar.o . 您的makefile不具有foo.obar.o依赖项。

This 这个

all: $(OBJS)
    $(CC) $(OBJS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(LINKER_FLAGS) -o $(OUTPUTFILE)

says all depends on $(OBJS) . all取决于$(OBJS) So when one of the files in $(OBJS) changes, that step is run. 因此,当$(OBJS)中的文件之一更改时,将运行该步骤。

This says foo.o depends on nothing: 这说foo.o无关紧要:

foo.o:
    $(CC) -c foo.cpp $(INCLUDE_PATHS) $(COMPILER_FLAGS) $(LIBRARY_PATHS) $(LINKER_FLAGS)

You need to add the dependency: 您需要添加依赖项:

foo.o: foo.cpp
    $(CC) -c foo.cpp $(INCLUDE_PATHS) $(COMPILER_FLAGS) $(LIBRARY_PATHS) $(LINKER_FLAGS)

Note that the spaces after the : usually need to be a tab, not actual space(s). 请注意:之后的空格通常必须是制表符,而不是实际空格。

You need to add dependencies to your target. 您需要向目标添加依赖项。 Make has the syntax Make具有语法

target : prerequisite
    command

So in your case: 因此,在您的情况下:

foo.o: foo.cpp
    $(CC) -c $< $(INCLUDE_PATHS) $(COMPILER_FLAGS) $(LIBRARY_PATHS) $(LINKER_FLAGS)

same with bar bar

the $< is a placeholder for the first prerequisite. $<是第一个前提条件的占位符。 So you don't have to type foo.cpp twice. 因此,您不必两次键入foo.cpp

You can checkout more automatic variables here: https://www.gnu.org/software/make/manual/make.html#Automatic-Variables 您可以在此处检出更多自动变量: https : //www.gnu.org/software/make/manual/make.html#Automatic-Variables

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM