Skip to content

Commit c8bc922

Browse files
committed
if --with_boost is specified, search *only* the specified directory hierarchy for libraries.
Arguably, if --with_boost is specified, the user wants to use only that boost installation, and no other. This changeset implements this behavior. The original code in _BOOST_FIND_LIBS prepended the --with_boost path to the default list of paths, resulting in all of the paths being searched if the library wasn't found in that specified by --with_boost. Because the search for a library begins with the most specialized version: boost_$boost_lib_$boost_tag_$boost_mt_$boost_rtopt_$boost_ver_ boost_$boost_lib_$boost_tag_$boost_rtopt_$boost_ver_ boost_$boost_lib_$boost_tag_$boost_mt_$boost_ver_ boost_$boost_lib_$boost_tag_$boost_ver_ if the user's preferred boost installation has a less specialized version of a library than one provided in the default path, the latter will be chosen instead. This may lead to a mismatch between the headers discovered in the --with_boost hierarchy and the library discovered in the default path, if they are for different versions of boost, leading to link problems if the latter is for an earlier version . Additionally, this will silently invalidate a request for a specific version of boost in BOOST_REQUIRE, as it will be fulfilled by the headers, but not by the library. The new code does the following: * It will only search the --with_boost hierarchy if that is provided; * It will (following the suggestion of issue #49 by mateidavid) use the absolute path to the library so that the linker's default library paths are not searched if the library is not found in the --with_boost hierarchy * It adds a second path "$with_boost/lib" to the search path, as that seems to be a standard place for libraries N.B. There is still a potential for mishap if --with_boost is *not* specified, namely that if there exist multiple boost installations and some do not have all of the libraries, it is possible to end up with libraries selected from multiple installations.
1 parent 1489691 commit c8bc922

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

build-aux/boost.m4

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ m4_define([_BOOST_SERIAL], [m4_translit([
4747

4848
m4_pattern_forbid([^_?(BOOST|Boost)_])
4949

50+
# _BOOST_SHELL_FUNCTIONS
51+
# --------------------------------------------------------
52+
#
53+
# Useful shell functions. Call
54+
# AC_REQUIRE([_BOOST_SHELL_FUNCTIONS])
55+
# before using
56+
AC_DEFUN([_BOOST_SHELL_FUNCTIONS],
57+
[_boost_join_path() { _boost_join_path_save_IFS=$IFS; IFS=@ ; echo "$[]*" ; IFS=$_boost_join_path_save_IFS ; } ]
58+
)
59+
5060

5161
# _BOOST_SED_CPP(SED-PROGRAM, PROGRAM,
5262
# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
@@ -370,7 +380,8 @@ AC_DEFUN([BOOST_FIND_LIB],
370380
# to enforce -mt (for instance on MacOSX, libboost_thread.dylib
371381
# doesn't exist but there's -obviously- libboost_thread-mt.dylib).
372382
AC_DEFUN([_BOOST_FIND_LIBS],
373-
[Boost_lib=no
383+
[AC_REQUIRE([_BOOST_SHELL_FUNCTIONS])
384+
Boost_lib=no
374385
case "$3" in #(
375386
(mt | mt-) boost_mt=-mt; boost_rtopt=;; #(
376387
(mt* | mt-*) boost_mt=-mt; boost_rtopt=`expr "X$3" : 'Xmt-*\(.*\)'`;; #(
@@ -435,27 +446,37 @@ for boost_rtopt_ in $boost_rtopt '' -d; do
435446
case $boost_failed_libs in #(
436447
(*@$boost_lib@*) continue;;
437448
esac
438-
# If with_boost is empty, we'll search in /lib first, which is not quite
439-
# right so instead we'll try to a location based on where the headers are.
440-
boost_tmp_lib=$with_boost
441-
test x"$with_boost" = x && boost_tmp_lib=${boost_cv_inc_path%/include}
442-
for boost_ldpath in "$boost_tmp_lib/lib" '' \
443-
/opt/local/lib* /usr/local/lib* /opt/lib* /usr/lib* \
444-
"$with_boost" C:/Boost/lib /lib*
449+
# If with_boost is specified; search *only* within that hierarchy,
450+
# otherwise search the "standard" places, starting with a location
451+
# based upon where the headers are.
452+
AS_IF( [ test x"$with_boost" = x ],
453+
[ boost_ldpaths=`_boost_join_path ${boost_cv_inc_path%/include} '' \
454+
/opt/local/lib* /usr/local/lib* /opt/lib* /usr/lib* \
455+
C:/Boost/lib /lib*` ],
456+
[ boost_ldpaths=`_boost_join_path "$with_boost" "$with_boost/lib"` ]
457+
)
458+
459+
save_IFS=$IFS
460+
IFS=@
461+
for boost_ldpath in `echo "$boost_ldpaths"`
445462
do
463+
IFS=$save_IFS
446464
# Don't waste time with directories that don't exist.
447465
if test x"$boost_ldpath" != x && test ! -e "$boost_ldpath"; then
448466
continue
449467
fi
450468
boost_save_LDFLAGS=$LDFLAGS
469+
# use an absolute path to the requested library to avoid finding it
470+
# in the linker's default search path
451471
# Are we looking for a static library?
452472
case $boost_ldpath:$boost_rtopt_ in #(
453473
(*?*:*s*) # Yes (Non empty boost_ldpath + s in rt opt)
454-
Boost_lib_LIBS="$boost_ldpath/lib$boost_lib.$libext"
455-
test -e "$Boost_lib_LIBS" || continue;; #(
456-
(*) # No: use -lboost_foo to find the shared library.
457-
Boost_lib_LIBS="-l$boost_lib";;
474+
Boost_lib_LIBS="$boost_ldpath/lib$boost_lib.$libext" ;;
475+
(*) # No:
476+
Boost_lib_LIBS="$boost_ldpath/lib$boost_lib$shrext_cmds" ;;
458477
esac
478+
# Don't waste time with libraries that don't exist
479+
test -e "$Boost_lib_LIBS" || continue
459480
boost_save_LIBS=$LIBS
460481
LIBS="$Boost_lib_LIBS $LIBS"
461482
test x"$boost_ldpath" != x && LDFLAGS="$LDFLAGS -L$boost_ldpath"

0 commit comments

Comments
 (0)