Makefile 更新了库依赖项

发布于 2024-09-08 18:02:16 字数 778 浏览 7 评论 0原文

我有一个很大的 makefile,它构建几个库,安装它们,然后继续构建链接到这些已安装库的对象。我的麻烦是我想使用“-lfoo -lbar”作为 g++ 标志来链接两个已安装的库,但依赖关系变得混乱。如果我更改库 foo 所依赖的标头“42.h”,那么 make 当然会重建并安装它,但它不会似乎注意到我的对象“marvin”使用了“- lfoo" 和 marvin 与旧版本保持链接...:(

到目前为止,我一直在做:

$(myObject): $(localSrc) /explicit/path/to/lib/libfoo.a
            $(CXX) $(CPPFLAGS) $(INCFLAGS) -o $@ $^ $(LINKFLAGS) $(LINKLIBS)

但我现在已经不再是一个可行的选择了。我需要简单地添加库“-lfoo -lbar”到 LINKFLAGS 变量并让链接器弄清楚事情?

同时,我给一些命令起了别名来显式地清除有问题的目标文件,然后调用 make,但这变得很愚蠢。我时间紧迫,但如果有必要,我可以在周五晚上或周六早上发布一个小例子,

因此,我觉得我又回到了一些糟糕的 Windows dll 版本。链接器会注意到构建对象所针对的库的版本,并在这些库发生变化时重新链接它?

更新:所以直到现在我还没有机会使建议崩溃。我正在做的事情的缺点是使用静态库。所以我不能使用ldd。所以我重写了我的Makefile并找到了解决这个问题的方法。如果我有时间,我会发布我所做的事情。

I have a large makefile which builds several libraries, installs them, and then keeps on building objects which link against those installed libraries. My trouble is that I want to use "-lfoo -lbar" as g++ flags to link against the two installed libraries, but the dependencies get messed up. If I change a header "42.h" which the library foo depends on, then of course make will rebuild and install it, but it does not appear to notice that my object "marvin" used "-lfoo" and marvin is left linked against the old version... :(

Thus far, I've been doing:

$(myObject): $(localSrc) /explicit/path/to/lib/libfoo.a
            $(CXX) $(CPPFLAGS) $(INCFLAGS) -o $@ $^ $(LINKFLAGS) $(LINKLIBS)

But I'm at a point where this is no longer a viable option. I need to simply add libraries "-lfoo -lbar" to the LINKFLAGS variable and have the linker figure things out?

In the mean time, I've aliased a few commands to explicitly blow away the object file(s) in question and then call make, but this is getting silly. I'm pressed for time, but if necessary I could post a small example perhaps Friday evening or Saturday morning.

Hence, I feel like I'm back in some bad version of windows dll hell. Is there something I can do to make the linker take notice of the version of the libraries that an object was built against and relink it if those libraries change??

Updated: So I hadn't had a chance to crash the suggestions until now. The drawback of what I'm doing is using static libraries. So I can't use ldd. So I rewrote my Makefile and found a way around this problem. If I get time, I'll post what I did.

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

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

发布评论

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

评论(3

淡水深流 2024-09-15 18:02:16

这个怎么样:

LIBS = foo bar blah # and so on

LINKFLAGS = $(addprefix -l,$(LIBS))

LIBPATHS = $(patsubst %,/explicit/path/to/lib/lib%.so, $(LIBS))

$(myObject): $(localSrc) $(LIBPATHS)
        $(CXX) $(CPPFLAGS) $(INCFLAGS) -o $@ $^ $(LINKFLAGS) $(LINKLIBS)

How about this:

LIBS = foo bar blah # and so on

LINKFLAGS = $(addprefix -l,$(LIBS))

LIBPATHS = $(patsubst %,/explicit/path/to/lib/lib%.so, $(LIBS))

$(myObject): $(localSrc) $(LIBPATHS)
        $(CXX) $(CPPFLAGS) $(INCFLAGS) -o $@ $^ $(LINKFLAGS) $(LINKLIBS)
枕梦 2024-09-15 18:02:16

据我所知,make 通常不太擅长自动检测这样的依赖关系。 (这并不是真正的 make 的工作;make 是一个更高级别的工具,它不知道它所生成的命令的细节或这些命令的作用。)我

想到了两个选项。

首先,您可以在 $(myObject) 上运行 ldd,将其库列表保存到文本文件中,然后将其作为依赖项列表返回到 makefile 中。 (这类似于使用 -MD 将头文件列表保存到文本文件,然后将其反馈到 makefile 作为源文件编译的附加规则,如 Sam Miller 所建议的。)

其次,您可以使用 LINKLIBS 变量一直在使用,并且使用GNU Make的函数来让同一变量适用于依赖项和命令行选项。例如:

LINKLIBS := /explicit/path/to/lib/libfoo.so
$(myObject): $(localSrc) $(LINKLIBS)
        $(CXX) $(CPPFLAGS) $(INCFLAGS) -o $@ $^ $(LINKFLAGS) $(patsubst %,-l:%,$(LINKLIBS))

As far as I know, make in general isn't very good at automatically detecting dependencies like this. (It's not really make's job; make is a higher-level tool that's not aware of the specifics of the commands that it's spawning or what those commands do.)

Two options come to mind.

First, you could run ldd on $(myObject), save its list of libraries to a text file, then feed that back into your makefile as a list of dependencies. (This is similar to using -MD to save a list of header files to a text file then feeding that back into the makefile as additional rules for source file compilation, as Sam Miller suggested.)

Second, you could use a LINKLIBS variable as you've been using, and use GNU Make's functions to let the same variable work for both dependencies and command-line options. For example:

LINKLIBS := /explicit/path/to/lib/libfoo.so
$(myObject): $(localSrc) $(LINKLIBS)
        $(CXX) $(CPPFLAGS) $(INCFLAGS) -o $@ $^ $(LINKFLAGS) $(patsubst %,-l:%,$(LINKLIBS))
对你的占有欲 2024-09-15 18:02:16

您可以尝试 gcc 依赖项生成参数,例如 -MD,我不清楚您是否正在使用它们。

You might try the gcc dependency generation arguments like -MD, it's not clear to me if you are using them.

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