我从单个目标文件创建一个静态库。生成的 .a 文件具有分辨率为一秒(截断到前一秒)的时间戳,而 .o 文件则没有。
实际上,它使 .a 文件看起来比 .o 文件旧,并且下次 I 时会重建 lib make
。
我听说 Mac 可能存在这样的问题,但我使用的是 Ubuntu,x64。
为了了解发生了什么,我做了一个更简单的项目来展示这种行为。但在这种情况下,一切都按我的预期工作:
gauthier@sobel:~/tmp/ar_test $ ls
hello.c makefile
gauthier@sobel:~/tmp/ar_test $ make
gcc -c hello.c -o hello.o -g -Wall -Wextra -Werror -O3 -lrt
ar -cvq hello.a hello.o
a - hello.o
gauthier@sobel:~/tmp/ar_test $ ls --full-time
total 28
-rw-rw-r-- 1 gauthier gauthier 11940 2014-11-21 09:55:22.131715135 +0100 hello.a
-rw-rw-r-- 1 gauthier gauthier 81 2014-11-20 15:14:34.419613737 +0100 hello.c
-rw-rw-r-- 1 gauthier gauthier 5864 2014-11-21 09:55:22.131715135 +0100 hello.o
-rw-rw-r-- 1 gauthier gauthier 254 2014-11-20 15:17:47.533185970 +0100 makefile
gauthier@sobel:~/tmp/ar_test $ make
make: Nothing to be done for `all'.
它在那里工作,hello.a
时间戳等于hello.o
.
回到我原来的项目。我不知道有什么不同,但是库的时间戳在几秒钟后用零填充:
gauthier@sobel:~/code/myproj (master) $ ls
makefile README.md test myproj.c myproj.h
gauthier@sobel:~/code/myproj (master) $ make
gcc -c myproj.c -o myproj.o -g -Wall -Wextra -Werror -O3 -lrt -pthread
ar -cvqU libmyproj.a myproj.o
a - myproj.o
gauthier@sobel:~/code/myproj (master) $ ls --full-time
total 64
-rw-rw-r-- 1 gauthier gauthier 18852 2014-11-21 10:03:59.000000000 +0100 libmyproj.a
-rw-rw-r-- 1 gauthier gauthier 1363 2014-11-21 09:53:09.397383831 +0100 makefile
-rw-rw-r-- 1 gauthier gauthier 106 2014-11-20 13:49:15.299969786 +0100 README.md
drwxrwxr-x 2 gauthier gauthier 4096 2014-11-20 13:49:15.303969736 +0100 test
-rw-rw-r-- 1 gauthier gauthier 4741 2014-11-20 13:49:15.303969736 +0100 myproj.c
-rw-rw-r-- 1 gauthier gauthier 3584 2014-11-20 15:05:10.554702000 +0100 myproj.h
-rw-rw-r-- 1 gauthier gauthier 18648 2014-11-21 10:03:59.861206394 +0100 myproj.o
gauthier@sobel:~/code/myproj (master) $ make
ar -cvqU libmyproj.a myproj.o
a - myproj.o
注意这里的时间戳libmyproj.a
:10:03:59.000000000。
我已经尝试了这两个选项-U
和-D
to ar
, to no av (不是我真的认为它应该有所作为)。
经过进一步调查,问题似乎取决于文件放置在哪个目录中:
如果我复制
~/code/myproj/myproj.o
到 test dir 的位置~/tmp/ar_test/myproj.o
并在ar -cvq libmyproj.a myproj.o
那里运行,则时间戳是正确的。如果我复制
~/tmp/ar_test/hello.o
到原始项目的位置~/code/myproj/hello.o
并在ar -cvq libhello.a hello.o
那里运行,则时间戳不正确。
换句话说:ar
当我在时生成截断的时间戳~/code/myproj
,但在我在时不生成~/tmp/ar_test
。
根据我所在的目录,什么可以使 lib 丢失时间戳的下半部分?