在远程 Linux 机器上编译 C++ - “检测到时钟偏差”警告

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3824500/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 23:40:03  来源:igfitidea点击:

Compiling C++ on remote Linux machine - "clock skew detected" warning

linuxmakefile

提问by DMA57361

I'm connected to my university's small Linux cluster via PuTTY and WinSCP, transferring files using the latter and compiling and running them with the former. My work so far has been performed in the university's labs, but today I have been doing some work at home that generated an interesting warning.

我通过 PuTTY 和 WinSCP 连接到我大学的小型 Linux 集群,使用后者传输文件并使用前者编译和运行它们。到目前为止,我的工作是在大学实验室进行的,但今天我在家中做了一些工作,产生了一个有趣的警告。

I uploaded an entire folder of stuff and, upon running the makecommand, I get this as the last line of output:

我上传了一个完整的文件夹,在运行make命令时,我将其作为输出的最后一行:

make: warning: Clock skew detected. Your build may be incomplete.

制作:警告:检测到时钟偏差。您的构建可能不完整。

The resulting binary works correctly, and there doesn't seem to be any other unexpected errors in the build process.

生成的二进制文件可以正常工作,并且在构建过程中似乎没有任何其他意外错误。

I seem to be able to trigger the error by building after uploading some new / replacement files (I edit everything locally then upload the new version), so I'm wondering if it's something just as simple as mismatched file modification times? Or something more concerning?

我似乎能够通过在上传一些新文件/替换文件后构建来触发错误(我在本地编辑所有内容然后上传新版本),所以我想知道这是否与文件修改时间不匹配一样简单?或者更令人担忧的事情?

So, should I be worried? How do I fix/prevent this?

那么,我应该担心吗?我如何解决/防止这种情况?

采纳答案by Tyler McHenry

That message is usually an indication that some of your files have modification times later than the current system time. Since makedecides which files to compile when performing an incremental build by checking if a source files has been modified more recently than its object file, this situation can cause unnecessary files to be built, or worse, necessary files to notbe built.

该消息通常表示您的某些文件的修改时间晚于当前系统时间。由于make在执行增量构建时通过检查源文件的修改时间是否比其目标文件更近来决定编译哪些文件,因此这种情况可能会导致构建不必要的文件,或者更糟的是,无法构建必要的文件。

However, if you are building from scratch (not doing an incremental build) you can likely ignore this warning without consequence.

但是,如果您是从头开始构建(而不是进行增量构建),您可能会忽略此警告而不会产生任何后果。

回答by Soo Wei Tan

This is usually simply due to mismatching times between your host and client machines. You can try to synchronize the times on your machines using ntp.

这通常只是由于您的主机和客户端机器之间的时间不匹配。您可以尝试使用ntp同步您机器上的时间。

回答by z -

According to user m9dhatter on LinuxQuestions.org:

根据LinuxQuestions.org 上的用户 m9dhatter 的说法

"make" uses the time stamp of the file to determine if the file it is trying to compile is old or new. if your clock is bonked, it may have problems compiling.

if you try to modify files at another machine with a clock time ahead by a few minutes and transfer them to your machine and then try to compile it may cough up a warning that says the file was modified from the future. clock may be skewed or something to that effect ( cant really remember ). you could just ls to the offending file and do this:

#touch <filename of offending file>

“make”使用文件的时间戳来确定它试图编译的文件是旧的还是新的。如果您的时钟坏了,则编译可能会出现问题。

如果您尝试在另一台机器上修改文件并将时钟时间提前几分钟并将它们传输到您的机器,然后尝试编译它可能会发出警告,表明该文件是从未来修改的。时钟可能会歪斜或出现这种情况(真的记不清了)。你可以 ls 到有问题的文件并执行以下操作:

#touch <违规文件的文件名>

回答by fschmitt

Make checks if the result of the compilation, e.g. somefile.o, is older than the source, e.g. somefile.c. The warning above means that something about the timestaps of the files is strange. Probably the system clocks of the University server differs from your clock and you e.g. push at 1 pm a file with modification date 2 pm. You can see the time at the console by typing date.

Make 检查编译结果(例如 somefile.o)是否比源(例如 somefile.c)旧。上面的警告意味着文件的时间戳有些奇怪。可能大学服务器的系统时钟与您的时钟不同,例如您在下午 1 点推送修改日期为下午 2 点的文件。您可以通过键入日期在控制台查看时间。

回答by janneb

Typically this occurs when building in a NFS mounted directory, and the clocks on the client and the NFS server are out of sync.

通常,在 NFS 挂载目录中构建时会发生这种情况,并且客户端和 NFS 服务器上的时钟不同步。

The solution is to run an NTP client on both the NFS server and all clients.

解决方案是在 NFS 服务器和所有客户端上运行 NTP 客户端。

回答by Ed Heal

I have had this in the past - due to the clocks being out on the machines. Consider setting up NTP so that all machines have the same time.

我过去曾遇到过这种情况 - 因为机器上的时钟已经过时了。考虑设置 NTP 以便所有机器都具有相同的时间。

回答by Brijesh Valera

Simple solution:

简单的解决方案:

# touch filename

will do all OK.

一切都会好起来的。

For more info: http://embeddedbuzz.blogspot.in/2012/03/make-warning-clock-skew-detected-your.html

欲了解更多信息:http: //embeddedbuzz.blogspot.in/2012/03/make-warning-clock-skew-detected-your.html

回答by Surjit

The solution is to run an NTP client , just run the command as below

解决办法是运行一个NTP客户端,运行如下命令

#ntpdate 172.16.12.100

172.16.12.100 is the ntp server

172.16.12.100是ntp服务器

回答by BlushONine

Replace the watch battery in your computer. I have seen this error message when the coin looking battery on the motherboard was in need of replacement.

更换电脑中的手表电池。当主板上的硬币电池需要更换时,我看到了此错误消息。

回答by Serge Stroobandt

Install the Network Time Protocol

安装网络时间协议

This also happened to me when running makeon a Samba SMB CIFS share on a server. A durable solution consists in installing the ntpdaemon on both the server and the client. (Please, note that this problem is not solved by running ntpdate. This would resolve the time difference only temporarily, but not in the future.)

make在服务器上的 Samba SMB CIFS 共享上运行时,这也发生在我身上。持久的解决方案包括在ntp服务器和客户端上安装守护程序。(请注意,运行 不能解决此问题ntpdate。这只能暂时解决时差,但不会在将来解决。)

For Ubuntu and Debian-derived systems, simply type the following line at the command line:

对于 Ubuntu 和 Debian 派生系统,只需在命令行输入以下行:

$ sudo apt install ntp

Moreover, one will still need to issue the command touch *once (and only once) in the affected directory to correct the file modification times once and for all.

此外,仍然需要touch *在受影响的目录中发出一次(并且仅一次)命令以一劳永逸地更正文件修改时间。

$ touch *

For more information about the differences between ntpand ntpdate, please refer to:

有关ntp和之间差异的更多信息ntpdate,请参阅: