Adding a path to AC_CHECK_LIB

I have the following problem with configure.ac:

I would like to add a library search path, because the libraries that I have to use are in some crazy folders. My idea is to do this with the 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 points the way to the library, of course I would like to know 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 CPLEX_LIBS to the library search path AC_CHECK_LIB. Is it possible?

+6
source share
1 answer

The user must respond to the script configuration where the libraries are located. The user has access to many options, the most common of which are:

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

There is no reason that the maintainer could modify the build scripts at all to accommodate the user at this stage, and many good reasons did not try to do anything. If you (as a user) find that your libraries are in many places, you can install LDFLAGS in your environment or in config.site. Your toolchain may have other mechanisms (for example, if you use gcc, you can simply set LIBRARY_PATH). The infrastructure provided by autoconf already provides many mechanisms to solve this problem, and it is better for the package developer not to reinvent the wheel and provide non-standard interfaces.

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

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

and this is wrong, because now you have the -l flag in LDFLAGS, but the -l arguments belong to LIBS . Also, if you have another library, libfoo and $ FOO_LIBS pointing to a different location, there is simply no way to fix this problem: LDFLAGS will get -L / cplex and -L / foo, and the user will not know which one on the first location and cannot guarantee communication with one library over another. In short, do not use CPLEX_LIBS: train the user to use LDFLAGS. In addition, it is more convenient to enter:

 configure LDFLAGS='-Lpath1 -Lpath2' 

what to dial

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

and the latter hides things and leads to an uneducated population. I never understood why people like to embed these --with-lib = / p / a / t / h options in their assemblies: they give nothing.

+14
source

Source: https://habr.com/ru/post/913462/


All Articles