Makefile 更新了库依赖 [英] Makefile updated library dependency

查看:58
本文介绍了Makefile 更新了库依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)

但我已经到了这不再是一个可行的选择的地步.我需要简单地将库-lfoo -lbar"添加到 LINKFLAGS 变量并让链接器解决问题?

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?

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

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.

因此,我觉得我又回到了 Windows dll 地狱的某个坏版本.我可以做些什么来让链接器注意到构建对象的库版本并在这些库发生更改时重新链接它??

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??

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

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.

推荐答案

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

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.)

我想到了两个选项.

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

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.)

其次,您可以使用一直使用的 LINKLIBS 变量,并使用 GNU Make 的 functions 让相同的变量同时适用于依赖项和命令行选项.例如:

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))

这篇关于Makefile 更新了库依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆