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])
])
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
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.
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
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'
than it is to type
configure --with-cplex=path1 --with-foo=path2
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With