Skip to content

Commit

Permalink
Fix building shared libraries on macOS with --enable-libtorch
Browse files Browse the repository at this point in the history
The configure code was unconditionally adding `-Wl;--no-as-needed` to the flags, even though
these are not valid on macOS.
  • Loading branch information
Luthaf committed Oct 10, 2024
1 parent 56789e9 commit 74ca55f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 31 deletions.
35 changes: 7 additions & 28 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -2341,7 +2341,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu


# PLUMED_CHECK_LDFLAGS(flag)
# use it to check if a flag is available on this compiler
# use it to check if a flag is available for linking


# PLUMED_SEARCH_LIBS(function,search-libs[,action-if-found][,action-if-not-found][,other-libraries])
Expand Down Expand Up @@ -9664,26 +9664,13 @@ fi
if test $libtorch = true ; then
# disable as-needed in linking libraries (both static and shared)

save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS -Wl,--no-as-needed"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX accepts -Wl,--no-as-needed" >&5
$as_echo_n "checking whether $CXX accepts -Wl,--no-as-needed... " >&6; }
save_LDFLAGS="$LDFLAGS"
LDFLAGS="$LDFLAGS -Wl,--no-as-needed"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether LDFLAGS can contain -Wl,--no-as-needed" >&5
$as_echo_n "checking whether LDFLAGS can contain -Wl,--no-as-needed... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
if ac_fn_cxx_try_compile "$LINENO"; then :

cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
Expand All @@ -9696,20 +9683,12 @@ if ac_fn_cxx_try_link "$LINENO"; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: not linking" >&5
$as_echo "not linking" >&6; }; CXXFLAGS="$save_CXXFLAGS"
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }; LDFLAGS="$save_LDFLAGS"
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext

else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }; CXXFLAGS="$save_CXXFLAGS"

fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext

LDSHARED="$LDSHARED -Wl,--no-as-needed "

# CUDA and CPU libtorch libs have different libraries
# first test CUDA program
Expand Down
5 changes: 2 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ AC_DEFUN([PLUMED_CHECK_CFLAG], [
])

# PLUMED_CHECK_LDFLAGS(flag)
# use it to check if a flag is available on this compiler
# use it to check if a flag is available for linking
AC_DEFUN([PLUMED_CHECK_LDFLAGS], [
save_LDFLAGS="$LDFLAGS"
LDFLAGS="$LDFLAGS $1"
Expand Down Expand Up @@ -935,8 +935,7 @@ fi
#added by luigibonati
if test $libtorch = true ; then
# disable as-needed in linking libraries (both static and shared)
PLUMED_CHECK_CXXFLAG([-Wl,--no-as-needed])
LDSHARED="$LDSHARED -Wl,--no-as-needed "
PLUMED_CHECK_LDFLAGS([-Wl,--no-as-needed])

# CUDA and CPU libtorch libs have different libraries
# first test CUDA program
Expand Down

0 comments on commit 74ca55f

Please sign in to comment.