GNU将存档成员作为目标

发布于 2025-01-28 06:46:27 字数 984 浏览 1 评论 0 原文

我在使用。问题在于,在某些计算机上(例如运行MacOS,Solaris),它可以正常工作,即构建库,下一个 make 给出 对'all'all'>无需完成。

但是,在Linux盒子上不始终重建所有内容。在所有机器上,我都使用GNU。

的示例,

这里有一个源文件 foo.c makefile foo.c

void foo() {}

makefile

all: libfoo.a

libfoo.a(%.o) : %.o
        $(AR) cr $@ $^

libfoo.a: libfoo.a(foo.o)
        ranlib libfoo.a

任何人可以确认吗? (或告诉我我做了什么明显的愚蠢错误...?)

在Solaris上运行

theon$ make
gcc    -c -o foo.o foo.c
ar cr libfoo foo.o
ranlib libfoo
rm foo.o
theon$ make
make: Nothing to be done for 'all'.

Linux

acker$ make
gcc    -c -o foo.o foo.c
ar cr libfoo foo.o
ranlib libfoo
rm foo.o
acker$ make
gcc    -c -o foo.o foo.c
ar cr libfoo foo.o
ranlib libfoo
rm foo.o

I have a problem with GNU make when using Archive Members as Targets. The problem is that on some machines (e.g. running MacOS, Solaris) it works fine, i.e. builds the library and the next make gives Nothing to be done for 'all'.

But not on the Linux boxes there make always rebuild everything. On all machines I am using GNU Make.

Here the example with one source file foo.c and the Makefile

foo.c

void foo() {}

Makefile

all: libfoo.a

libfoo.a(%.o) : %.o
        $(AR) cr $@ $^

libfoo.a: libfoo.a(foo.o)
        ranlib libfoo.a

Can anyone confirm that? (or tell me what obvious stupid mistake I have done ...?)

Run on Solaris

theon$ make
gcc    -c -o foo.o foo.c
ar cr libfoo foo.o
ranlib libfoo
rm foo.o
theon$ make
make: Nothing to be done for 'all'.

Run on Linux

acker$ make
gcc    -c -o foo.o foo.c
ar cr libfoo foo.o
ranlib libfoo
rm foo.o
acker$ make
gcc    -c -o foo.o foo.c
ar cr libfoo foo.o
ranlib libfoo
rm foo.o

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风为裳 2025-02-04 06:46:27

很可能不是您,而是您的GNU/Linux发行版很愚蠢,并将“确定性模式”设置为 ar 的默认行为。这是 ar 程序的配置时间选项,以确定其默认为“确定性”或“非确定性”( ar 的历史和正确默认行为)。一些发行版在其版本的 ar 版本中设置此配置选项并更改默认行为。

这会破坏 make (以及需要知道对象时间戳的任何其他工具)。

如果这是问题,您可以更改 ar 的调用以添加 u 选项以再次关闭确定模式:

ARFLAGS = crU

不幸的是, ar 命令无法理解此选项,因此您需要找到一种仅适用于使用GNU Binutils的方法。

您还应该随意向您的GNU/Linux分发投诉。

Most likely it's not you, it's that your GNU/Linux distribution is stupid and has set "deterministic mode" as the default behavior of ar. This is a configure-time option for the ar program, to determine whether it defaults to "deterministic" or "non-deterministic" (the historical and correct default behavior for ar). Some distributions made the ridiculous decision to set this configuration option in their version of ar, and change the default behavior.

This breaks make (and any other tool that needs to know the timestamps of objects).

If this is the problem, you can change your invocation of ar to add the U option to turn deterministic mode off again:

ARFLAGS = crU

Unfortunately it's likely that the ar commands on non-GNU systems won't understand this option so you'll need to find a way to add it only for the ones using GNU binutils.

You should also feel free to complain to your GNU/Linux distribution about this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文