Gerald,
On 4/2/2009 3:45 PM, Gerald I. Evenden wrote:
After trying so many options related to libraries I am exhausted.
I have a simple program that needs to link with a shared library installed
in /usr/local/lib.
When using my own simple Makefile and simply adding "-lproject -lm" everything
works fine (libproject is the shared library).
But regardless of how many tests, etc., I do in the .ac and .am files I cannot
get the final Makefile to link with "project."
I presume that the reason you link with both libproject and the math
library is because libproject requires libm. This could explain why your
configure.ac tests are failing to "find" libproject. Try adding this
test to configure.ac:
AC_SEARCH_LIBS([any_visible_function_in_libproject],[project],[AC_DEFINE([HAVE_LIBPROJECT])],,[-lm])
Tests in configure.ac "look" for libraries by actually building programs
that attempt to link the specified symbol from the specified list of
libraries. If the program links, then the test succeeds. The default
action in successful cases for AC_SEARCH_LIBS is to add "-lprojects" to
the LIBS variable, which is automatically added to your compiler command
line (at least by Automake-generated makefiles). If the library that
AC_SEARCH_LIBS attempts to link to requires other non-default libraries
(like libm, for instance), then you have to add this list of linker
commands to the "other-libraries" argument, or the test will fail, even
if the function is found in the desired library.
The documentation for AC_SEARCH_LIBS indicates that, on successfully
testing for the desired library, this macro prepends -lproject to LIBS,
and then executes the shell code in the "action-if-found" parameter,
thus, you don't need to add -lproject to LIBS, because this is done by
the macro before any additional shell code you specify is executed.
You can also use the following macro, which generates shell code that is
a little less complex. But it's a bit harder to use correctly, as you
have to write the entire "action-if-found" functionality yourself. The
carriage returns are fairly important here:
AC_CHECK_LIB([project],[any_visible_function_in_libproject],
[LIBS=-lproject $LIBS
AC_DEFINE([HAVE_LIBPROJECT])],,[-lm])
AC_CHECK_LIB has no success functionality that executes even if you
supply the "action-if-found" argument. All of it's success functionality
is given by the default value of the argument. Thus, if you supply the
argument, you have to supply all of the appropriate functionality for a
successful check. In this case, the macro is supposed to prepend
-lproject to LIBS, and then define HAVE_LIBPROJECT.
Regards,
John