简体   繁体   English

使用自动工具链接生成的库

[英]Linking generated library using autotools

I have a following directory structure 我有以下目录结构

src/
    kernel/
    gui/

In kernel/ directory, I have generated a library named libkernel.a and in gui/ directory I have to use libkernel.a to generate libgui.a . 在kernel /目录中,我生成了一个名为libkernel.a的库,在gui /目录中,我必须使用libkernel.a生成libgui.a

I added this to the gui/Makefile.am 我将此添加到gui / Makefile.am

libgui_a_LIBADD = $(srcdir)/kernel/libkernel.a

But I am getting the following error 但是我收到以下错误

*** No rule to make target `kernel/libkernel.a', needed by `libgui.a'.  Stop.

So I don't understand how do I link libkernel.a properly. 所以我不明白如何正确链接libkernel.a

Edit/Explanation 编辑/说明

In gui/ directory I have one somegui.cpp file that uses xclass.h which is in kernel/ directory. 在gui /目录中,我有一个somegui.cpp文件,该文件使用kernel /目录中的xclass.h So in order to solve that issue I am asking how should I proceed. 因此,为了解决该问题,我想问我应该如何进行。

Try to use non-recursive automake to avoid these kind of problems. 尝试使用非递归自动制作来避免此类问题。

https://www.flameeyes.eu/autotools-mythbuster/automake/nonrecursive.html https://www.flameeyes.eu/autotools-mythbuster/automake/nonrecursive.html

Sidenode: use $(top_builddir) when referring to compiled objects. 旁节点:在引用编译对象时使用$(top_builddir)。 Otherwise your code will break when srcdir != builddir 否则,当srcdir!= builddir时,您的代码将中断

If you really have to do it recursive, than you can add a rule to gui/Makefile.am 如果确实需要递归执行,则可以向gui / Makefile.am添加规则

$(top_builddir)/kernel/libkernel.a:
        cd $(top_builddir)/kernel && $(MAKE)

Note: If you want to use parallel make (-j) you also need to make sure that in src/Makefile.am there is a dependency between the subdirs 注意:如果要使用并行make(-j),还需要确保在src / Makefile.am中,子目录之间存在依赖关系

.PHONY kernel gui
kernel:
      cd kernel && $(MAKE)
gui: kernel
      cd gui && $(MAKE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM