AC_CHECK_LIB vs AC_SEARCH_LIBS

I've noticed some rather frustrating results of using either AC_CHECK_LIB and AC_SEARCH_LIBS and I'm hoping that someone with a little more experience with this may be able to point me in the right direction...

The os project I'm working on currently uses AC_CHECK_LIB to check for the existence of the Boost Filesystem lib on the host machine. This doesn't seem to work at all on FreeBSD (it's not overly important at this point, but anyone know the specific cause of this?). After reading some docs, it seems that AC_SEARCH_LIBS is the recommended macro to use, so I switched to that. However, I noticed pretty quickly (well, when the linker fired up) that -lboost_filesystem wasn't being added to LIBS as reported in the docs.

Is this a known issue on FreeBSD (and is it only on BSD machines, or other Linux systems as well)?
 
FYI -

Code:
AC_SEARCH_LIBS([main], [boost_filesystem], , AC_MSG_ERROR([Unable to find Boost Filesystem library]))

Is the line I'm using that seems to detect the lib, but doesn't add -lboost_filesystem to LIBS.
 
As far as I know, you need to do that sort of thing manually. Here's an example from a configure.ac of mine:
Code:
AC_CHECK_LIB([pthread], [pthread_create], [LIBPTHREAD=true], [], [])
AM_CONDITIONAL([LINK_LIBPTHREAD], [test x$LIBPTHREAD = xtrue])
And in the appropriate Makefile.am:
Code:
if LINK_LIBPTHREAD
  USE_LIBPTHREAD=-lpthread
endif
#...
libwhatever_la_LIBADD=$(USE_LIBPTHREAD)
Or for a conditional build:
Code:
if LINK_LIBPTHREAD
  USE_LIBPTHREAD=libwhatever
endif

SUBDIRS=$(USE_LIBPTHREAD)
Kevin Barry
 
Now that I compare my code and yours, it's hard to tell if you have the library and the function switched. Is the library libmain.so?
Kevin Barry
 
As far as i know pretty specific things like pthreads or boost you should use an m4 script for it and i know there is one for boost but i dont use it, but i use one for pthreads. Some awkward libraries its handy to google for an m4 :)
 
A noob question if I may...

In statements such as [test x$LIBPTHREAD = xtrue],
what does the x prefix mean?

From what I understand the "test" is the standard shell command, but I did not find any explanation anywhere as to why we write xtrue here.
 
Oh... right...

If we don't add the x before the variable, we will get in trouble with the test command because it won't have enough arguments... And then we have to write "xtrue" since we are expecting the value to be "true", and we put an x in front.

This is the first time in a long while that Google does not come up with an explanation, and I actually have to use my brain...
 
Yep, the x is just there to prevent an empty string from messing up the comparisons.
 
Back
Top