libtool 不提供要链接的库依赖项

CAB*_*CAB 4 automake libtool

我在 ubuntu lucid 上使用 libtool 2.2.6b,在 ubuntu precision 上使用 libtool 2.4.2。清醒时,我的项目将正确链接。准确地说,它无法链接。这是演示我的问题的示例代码;

配置文件

AC_INIT([ltp], [0.0.1], [someone])
AM_INIT_AUTOMAKE
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([.m4])
AC_CONFIG_FILES([Makefile foo/Makefile bar/Makefile wah/Makefile])
AC_PROG_CXX
AC_PROG_LIBTOOL
AM_SANITY_CHECK
AC_LANG_CPLUSPLUS
AC_OUTPUT
Run Code Online (Sandbox Code Playgroud)

生成文件

SUBDIRS = foo bar wah
ACLOCAL_AMFLAGS = -I .m4
Run Code Online (Sandbox Code Playgroud)

foo/foo.h

#ifndef FOO_FOO_H_
#define FOO_FOO_H_
namespace Foo
{
  class Foo
  {
  public:
    Foo(long l);
  private:
    long l;
  };
}
#endif
Run Code Online (Sandbox Code Playgroud)

foo/foo.cpp

#include "foo/Foo.h"
namespace Foo
{
  Foo::Foo(long l) : l(l) {}
}
Run Code Online (Sandbox Code Playgroud)

foo/Makefile.am

lib_LTLIBRARIES = libfoo.la
libfoo_la_SOURCES = Foo.cpp
libfoo_la_CPPFLAGS =
libfoo_la_LDFLAGS = -release 0.0.1
libfoo_la_LIBADD =
Run Code Online (Sandbox Code Playgroud)

酒吧/酒吧.h

#ifndef BAR_BAR_H_
#define BAR_BAR_H_
#include "foo/Foo.h"
namespace Bar
{
  class Bar
  {
  public:
    Bar(const Foo::Foo & f);
  private:
    Foo::Foo f;
  };
}
#endif
Run Code Online (Sandbox Code Playgroud)

酒吧/酒吧.cpp

#include "bar/Bar.h"
namespace Bar
{
  Bar::Bar(const Foo::Foo & f) : f(f) { }
}
Run Code Online (Sandbox Code Playgroud)

酒吧/Makefile.am

lib_LTLIBRARIES = libbar.la
libbar_la_SOURCES = Bar.cpp
libbar_la_CPPFLAGS =
libbar_la_LDFLAGS = -release 0.0.1
libbar_la_LIBADD = -L../foo -lfoo
Run Code Online (Sandbox Code Playgroud)

哇音/main.cpp

#include "bar/Bar.h"
int main(int argc, char * argv[])
{
  Bar::Bar( 5 );
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

哇音/Makefile.am

bin_PROGRAMS = wah
wah_SOURCES = main.cpp
wah_CPPFLAGS =
wah_LDADD = -L../bar -lbar
Run Code Online (Sandbox Code Playgroud)

在 Lucid、wah 链接和 Precise 上,它失败了:

wah/main.cpp:5 undefined reference to `Foo::Foo::Foo(long)'
Run Code Online (Sandbox Code Playgroud)

我可以通过添加-L../foo -lfoo到来解决这个问题wah_LDADD,但实际上,libtool 不应该自动为我做这件事吗?关于“链接可执行文件”的 libtool 手册部分似乎表明这正是它应该做的。

adl*_*adl 5

在我用于开发的任何 Debian 机器上,我都必须手动编译和安装 Libtool,因为 Debian 提供的版本已打补丁并以破坏我的构建的方式忽略依赖项。

如果 Ubuntu 的版本相似,您可能也想从源代码安装 Libtool 。

  • 从那时起,我找到了一种方法来取消 Debian 补丁在我自己的项目中的影响,这样开发人员就不需要在他们工作的每台 Debian 机器上重新安装 libtool。http://git.lrde.epita.fr/?p=spot.git;a=commitdiff;h=0e74b76521341f670f6b76f8ef24a6dcf6e3813b (3认同)
  • 我*认为*麻烦的补丁是`link_all_deplibs.patch`,因为它将`$link_all_deplibs`设置为`no`。邮件 http://lists.gnu.org/archive/html/libtool/2007-09/msg00017.html 给出了这个中断的例子。 (2认同)