Automake AM_LDADD解决方法 [英] Automake AM_LDADD workaround

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

问题描述

我想为大量目标(单元测试C ++文件)设置相同的LDADD属性(单元测试库)。我首先虽然也许automake有AM_LDADD变量添加该库到文件中的所有目标,但不是这样。
在某些邮件列表中,我发现了一些简短的讨论,要求添加它:
http://gnu-automake.7480.n7.nabble.com/AM-LIBS-AM-LDADD-td3698.html

I want to set the same LDADD attribute (Unit test library) to a large number of targets (unit test C++ files). I first though that maybe automake has AM_LDADD variable to add that library to all the targets within the file but is not the case. In some mail list I found some short discussion asking to add it: http://gnu-automake.7480.n7.nabble.com/AM-LIBS-AM-LDADD-td3698.html

我的问题是,你如何处理?是否有任何方法避免手动添加LDADD属性到每个目标?

My question is, how do you deal with that? is it there any way to avoid manually adding LDADD attribute to each target?

到目前为止,我的Makefile.am看起来像:

So far my Makefile.am looks like:

 test1_SOURCES = ...
 test1_LDADD = -llibrary 
  ...
  ...
 test20_SOURCES = ...
 test20_LDADD = -llibrary 


推荐答案

AM_LDADD 变量只是 LDADD 。例如

The equivalent of an AM_LDADD variable is simply LDADD. e.g.,

LDADD = -llibrary

test1_SOURCES = ...
...
test20_SOURCES = ...

如果您需要覆盖 LDADD 对于特定程序: prog ,那么 prog_LDADD 将始终优先。

If you need to override LDADD for a particular program: prog, then prog_LDADD will always take precedence.

我总是假定因为没有 LDADD 标准环境变量传递到 configure - 你可以看到 configure --help - 没有真正的原因,一个 AM_LDADD 。这种方式有意义,因为 configure 脚本和任何选项,例如 - with-foo =< path>

I always assumed that since there was no LDADD standard environment variable passed to configure - as you can see with configure --help - there is no real reason for an AM_LDADD. This kind of makes sense, as the configure script, and any options, e.g., --with-foo=<path> should (ideally) work out the library dependencies.

另一方面,传递 CFLAGS via configure 可能仍需要一个 AM_CFLAGS ,它结合了 CFLAGS 编译器标志由configure脚本决定;或者甚至是 foo_CFLAGS 覆盖。由于配置必须通知您的自定义 CFLAGS

On the other hand, passing CFLAGS via configure might still need an AM_CFLAGS that combines CFLAGS and with other compiler flags determined by the configure script; or even a foo_CFLAGS override. Since configure must be informed of your custom CFLAGS.

此外,我不知道 test< n> 程序是否只有一个C ++源文件, ,您可以简化 Makefile.am

Also, I don't know if the test<n> programs only take a single C++ source file, but if so, you can simplify the Makefile.am with:

LDADD = -llibrary

check_PROGRAMS = test1 test2 ... test20
AM_DEFAULT_SOURCE_EXT = .cc # or .cpp

(如此处所述) 。

对于您的评论,您可以使用便利库,对于测试程序使用的常用代码尤其有用:

In regards to your comment, your can use a convenience library for that purpose - which is particularly useful for common code used by test programs:

noinst_LIBRARIES = libfoo.a  # or noinst_LTLIBRARIES = libfoo.la
libfoo_a_SOURCES = MyClass.hh MyClass.cc  # or libfoo_la_SOURCES

LDADD = ./libfoo.a -llibrary # or libfoo.la if using libtool.

... etc ...

这篇关于Automake AM_LDADD解决方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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