2014-04-24 61 views
10

我有一個工作Makefile,但有一個警告我無法修復。生成文件警告:警告:文件`main.cpp'在將來修改時間爲2.1e + 04秒

#Use the g++ compiler 
CC = g++ 

# Compiler flags: 
# -Wall (most warnings enabled) 
# -g (for debugging with gdb) 
CFLAGS = -Wall 

# Executable name: 
TARGET = deque_adt 

all: main.o deque_adt.o deque_adt 

$(TARGET): main.o deque_adt.o 
    $(CC) $(CFLAGS) main.o deque_adt.o -o $(TARGET) 

main.o: main.cpp deque_adt.h 
    $(CC) $(CFLAGS) main.cpp -c 

deque_adt.o: deque_adt.cpp deque_adt.h 
    $(CC) $(CFLAGS) deque_adt.cpp -c 

clean: 
    rm *.o *~ $(TARGET) 

錯誤:

make: Warning: File `main.cpp' has modification time 2.1e+04 s in the future 
g++ -Wall main.cpp -c 
g++ -Wall deque_adt.cpp -c 
g++ -Wall main.o deque_adt.o -o deque_adt 
make: warning: Clock skew detected. Your build may be incomplete. 

有人可以幫我找出這個問題?我試圖在元素之間切換,但它仍然給出相同的警告。

+4

這當您複製兩臺計算機之間建立產出情況,並在這些計算機上的時鐘不同意。 'make clean'應該強制使用本地時鐘重新生成所有文件,之後你不應該再次看到問題......除非你的電腦時鐘壞掉了。 –

+1

什麼是您的文件修改時間?這個錯誤是來自make(而不是gcc),並且告訴你,你的文件修改時間是未來的(這使得它不太喜歡它,因爲它使它困惑)。 –

+0

make clean將無法修復非生成的.cpp文件的修改時間。 –

回答

29

爲了擴大本福格特的回答是:

find /your/dir -type f -exec touch {} + 

將更新目錄中的所有文件的時間戳。你可以再次make clean && make

+1

這對於手頭的問題可能是巨大的矯枉過正。這是核選擇。 –

+1

@EtanReisner一點都不!這實際上是最便宜的選擇。通過觸摸和製作三個源文件,它可能會達到兩個CPU秒和十個人秒。 –

+0

你的發現是在目錄中的每個文件上調用'stat',然後全部觸摸它們。手動在單個文件上運行touch肯定比這更快。您的解決方案也只會越來越糟糕,因爲相對於具有錯誤時間戳的文件數量,項目變得更大。 –

0

嘗試使用以下命令:

rm Makefile 
sudo qmake yourproj. //or any command to create the makefile again 
make clean 
make 
+1

請解釋您的代碼如何回答問題。 –