Reputation: 1740
I'm trying to write an autoconf check to see if i can link from a library i'm developing to another base library. My check is:
AC_SUBST([LIBS],["${LIBS} -lMyLib"])
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([#include <mylib/library.hpp>],
[testFunction()])],
[AC_DEFINE([HAVE_MYLIB],[1],[Do we have libMyLib?])],
[AC_MSG_ERROR([Please install libMyLib before trying to build libMyLibJNI.])])
This works ok if libMyLib is installed in some standard location. If i build libMyLib and install it in a non-standard directory, then this check fails, even if i pass LDFLAGS to my configure script:
$ LDFLAGS="${PWD}/../target/cpp/lib" ./configure --prefix="${PWD}/../target/cpp"
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
...
configure: error: Please install libMyLib before trying to build libMyLibJNI.
How do i pass my LDFLAGS to configure tests?
Upvotes: 2
Views: 1494
Reputation: 3240
You You need to pass the -L
option to LDFLAGS
, not just a path; I also suggest to pass the variable to ./configure
rather than as environment:
$ ./configure --prefix="${PWD}/../target/cpp" LDFLAGS="-L${PWD}/../target/cpp/lib"
Alternatively, you can pass it to LIBS
too, as the search path can be passed in either variables correctly (the two variables are equivalent with the exception of where they are passed in the linker command line, but in the case of search path, either position is fine).
Also, you have at least one mistake in your check: you should not use AC_SUBST
that way, but rather just set LIBS="${LIBS} -lMyLib
(the substitution will always happen for that). But even more so, if your function can be checked without including the header, you should be using AC_CHECK_LIB
.
Upvotes: 1