将路径添加到AC_CHECK_LIB [英] Adding a path to AC_CHECK_LIB

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

问题描述

configure.ac存在以下问题:

I have the following problem with configure.ac:

我想添加一个库搜索路径,因为我必须使用的库位于一些疯狂的文件夹中.我的想法是使用一个选项来做到这一点:

I would like to add a library search path because the libraries I have to use are in some crazy folders. My idea is to do this with an option:

AC_ARG_WITH([cplex-lib-path],
  [AS_HELP_STRING([--with-cplex-libs], [location of the CPLEX library])],
  [CPLEX_LIBS="-L$withval --lcplex"],
  [])

如果有人指定了库路径,我当然想看看是否可以找到该库:

If someone specifies the library path I would of course like to see if the library can be found:

AC_CHECK_LIB([cplex], [CPXcreateprob], [],
[
  AC_MSG_ERROR([Could  not find CPLEX library])
])

但是,我想将CPLEX_LIBS添加到AC_CHECK_LIB的库搜索路径中.这可能吗?

However, I would like to add the CPLEX_LIBS to the library search path of AC_CHECK_LIB. Is this somehow possible?

推荐答案

告诉用户配置脚本库的位置是用户的责任.用户可以使用许多选项,其中最常见的是:

It is the user's responsibilty to tell the configure script where the libraries are. There are many options available to the user, with the most common being:

configure LDFLAGS=-L/p/a/t/h

在这一点上,维护人员绝对没有理由修改构建脚本以适应用户的需求,并且有很多充分的理由不进行任何操作.如果您(作为用户)发现您的库位于许多位置,则可以在您的环境或config.site中设置LDFLAGS.您的工具链可能还有其他机制(例如,如果您使用的是gcc,则可以简单地设置LIBRARY_PATH). autoconf提供的基础结构已经提供了解决此问题的大量机制,并且软件包维护者最好不要重新发明轮子并提供非标准接口.

There is absolutely no reason for the maintainer to modify the build scripts at all to accomodate a user on this point, and many good reasons for not trying to do anything. If you (as a user) find that your libraries are in many locations, you can set LDFLAGS in your environment, or in a config.site. Your toolchain probably has other mechanisms ( eg, if you are using gcc you can simply set LIBRARY_PATH). The infrastructure provided by autoconf already provides plenty of mechanisms for dealing with this issue, and the package maintainer is better off not reinventing the wheel and providing non-standard interfaces.

现在,我辩称您不应该做您想做的事情,我将告诉您如何去做. AC_CHECK_LIB将使用LDFLAGS中的值进行搜索,因此您可以执行以下操作:

Now that I've argued that you should not do what you are trying to do, I'll tell you how to do it. AC_CHECK_LIB will use the value in LDFLAGS for its search, so you can do:

LDFLAGS="$LDFLAGS $CPLEX_LIBS"     # this is a bug

,这是错误的,因为您现在在LDFLAGS中有一个-l标志,但是-l自变量属于LIBS.另外,如果您要使另一个库libfoo和$ FOO_LIBS指向其他位置,则根本没有歧义:LDFLAGS将获得-L/cplex和-L/foo,并且用户将不知道哪个库首先出现,将不能保证与一个库建立链接而无法与另一个库建立链接.简而言之,不要使用CPLEX_LIBS:教育您的用户使用LDFLAGS.另外,键入以下内容更方便:

and this is wrong because you now have a -l flag in LDFLAGS, but -l arguments belong in LIBS. Also, if you are going to have another library, libfoo, and $FOO_LIBS pointing to a different location, there is simply no way to disambiguate: LDFLAGS will get -L/cplex and -L/foo and the user will not know which one comes first and will not be able to guarantee linkage against one library over the other. In short, do not use CPLEX_LIBS: educate your user to use LDFLAGS. Also, it is more convenient to type:

configure LDFLAGS='-Lpath1 -Lpath2' 

比键入

configure --with-cplex=path1 --with-foo=path2

,后者混淆了事物并导致了未受教育的民众.我从来不明白为什么人们喜欢在其构建中加入这些--with-lib =/p/a/t/h选项:它们没有提供任何有用的信息.

and the latter obfuscates things and leads to an uneducated populace. I've never understood why people like putting in these --with-lib=/p/a/t/h options in their builds: they provide nothing useful.

这篇关于将路径添加到AC_CHECK_LIB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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