Makefile更新库依赖 [英] Makefile updated library dependency
问题描述
到目前为止,我一直在做:
$ $ $ $ $ $($)$($)$($)$($)$($) )-o $ @ $ ^ $(LINKFLAGS)$(LINKLIBS)
但是我在点,这不再是一个可行的选择,我需要简单地将库-lfoo -lbar添加到LINKFLAGS变量中,并使链接器显示出来。
平均而言,我已经别的几个命令来明确地吹走有问题的对象文件,然后调用make,但是这是愚蠢的,我按下了时间,但如果需要,我可以发布一个小例子也许是星期五晚上或星期六上午。
因此,我觉得我是回到一些坏版本的Windows dll地狱。有没有什么可以做的,使链接器注意到一个对象被创建的库的版本,如果这些库改变了它,并重新链接它。
更新:所以,直到现在,我还没有机会把建议摔倒。我正在做的是使用静态库的缺点。所以我不能使用 ldd
。所以我重写了我的Makefile并找到了解决这个问题的方法。如果我有时间,我会发布我做的。
据我所知,一般来说非常好地自动检测这样的依赖关系。 (这不是真正的工作; 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))
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.
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))
这篇关于Makefile更新库依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!