Makefile updated library dependency

前端 未结 3 1480
太阳男子
太阳男子 2021-01-22 05:03

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 wan

相关标签:
3条回答
  • 2021-01-22 05:28

    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)
    
    0 讨论(0)
  • 2021-01-22 05:30

    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))
    
    0 讨论(0)
  • 2021-01-22 05:30

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

    0 讨论(0)
提交回复
热议问题