From: wolf Date: Tue, 29 Apr 2003 16:19:55 +0000 (+0000) Subject: Invent a test to check for a weird linkage problem with functions in anonymous namesp... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=69850ef9177aae21747b1477c35d4294ebc3fdcb;p=dealii-svn.git Invent a test to check for a weird linkage problem with functions in anonymous namespaces, that some compilers (gcc3.2/3, icc) give the same name every time a file is compiled, even if we compile it for a different space dimension. This then leads to a linker problem. So work around that if necessary. git-svn-id: https://svn.dealii.org/trunk@7491 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/aclocal.m4 b/deal.II/aclocal.m4 index 866730a07e..caadf3e7f1 100644 --- a/deal.II/aclocal.m4 +++ b/deal.II/aclocal.m4 @@ -2377,6 +2377,58 @@ AC_DEFUN(DEAL_II_CHECK_FUNPTR_TEMPLATE_TEMPLATE_BUG, dnl +dnl ------------------------------------------------------------- +dnl We compile all the files in the deal.II subdirectory multiple +dnl times, for the various space dimensions. When a program +dnl needs the libs for more than one dimension, the symbols in +dnl these libs must be either static or weak. Unfortunately, some +dnl compilers don't mark functions in anonymous namespaces as +dnl static, and also mangle their names the same way each time, +dnl so we get into trouble with duplicate symbols. Check +dnl whether this is so. +dnl +dnl The check is a little more complicated than the usual one, +dnl since we can't use AC_TRY_COMPILE (we have to compile and link +dnl more than one file). +dnl +dnl Usage: DEAL_II_CHECK_ANON_NAMESPACE_BUG +dnl +dnl ------------------------------------------------------------- +AC_DEFUN(DEAL_II_CHECK_ANON_NAMESPACE_BUG, dnl +[ + AC_MSG_CHECKING(for anonymous namespace and name mangling bug) + + dnl Create the testfile + echo "namespace { int SYMBOL() {return 1;}; }" > conftest.cc + echo "static int f() { return SYMBOL(); }" >> conftest.cc + + dnl Then compile it twice... + $CXX -c conftest.cc -o conftest.1.$ac_objext + $CXX -c conftest.cc -o conftest.2.$ac_objext + + dnl Create a file with main() and also compile it + echo "int main () {}" > conftest.cc + $CXX -c conftest.cc -o conftest.3.$ac_objext + + dnl Then try to link everything + if (($CXX conftest.1.$ac_objext conftest.2.$ac_objext \ + conftest.3.$ac_objext -o conftest 2>&1 ) > /dev/null );\ + then + AC_MSG_RESULT(no) + else + AC_MSG_RESULT(yes. using workaround) + AC_DEFINE(DEAL_II_ANON_NAMESPACE_BUG, 1, + [Defined if the compiler needs to see the static + keyword even for functions in anonymous namespaces, + to avoid duplicate symbol errors when linking. + For the details, look at aclocal.m4 in the + top-level directory.]) + fi + rm -f conftest.1.$ac_objext conftest.2.$ac_objext conftest +]) + + + dnl ------------------------------------------------------------- dnl We have so many templates in deal.II that sometimes we need dnl to make it clear with which types a template parameter can diff --git a/deal.II/base/include/base/config.h.in b/deal.II/base/include/base/config.h.in index 8acd99eb5f..520ee6b9b1 100644 --- a/deal.II/base/include/base/config.h.in +++ b/deal.II/base/include/base/config.h.in @@ -31,6 +31,11 @@ +/* Defined if the compiler needs to see the static keyword even for functions + in anonymous namespaces, to avoid duplicate symbol errors when linking. For + the details, look at aclocal.m4 in the top-level directory. */ +#undef DEAL_II_ANON_NAMESPACE_BUG + /* Backward compatibility support for functions and classes that do not take an explicit mapping variable, but rather use a default Q1 mapping instead */ diff --git a/deal.II/configure b/deal.II/configure index 850bcbe26a..d4b9a7fab1 100755 --- a/deal.II/configure +++ b/deal.II/configure @@ -4906,6 +4906,35 @@ fi rm -f conftest.$ac_objext conftest.$ac_ext + echo "$as_me:$LINENO: checking for anonymous namespace and name mangling bug" >&5 +echo $ECHO_N "checking for anonymous namespace and name mangling bug... $ECHO_C" >&6 + + echo "namespace { int SYMBOL() {return 1;}; }" > conftest.cc + echo "static int f() { return SYMBOL(); }" >> conftest.cc + + $CXX -c conftest.cc -o conftest.1.$ac_objext + $CXX -c conftest.cc -o conftest.2.$ac_objext + + echo "int main () {}" > conftest.cc + $CXX -c conftest.cc -o conftest.3.$ac_objext + + if (($CXX conftest.1.$ac_objext conftest.2.$ac_objext \ + conftest.3.$ac_objext -o conftest 2>&1 ) > /dev/null );\ + then + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 + else + echo "$as_me:$LINENO: result: yes. using workaround" >&5 +echo "${ECHO_T}yes. using workaround" >&6 + +cat >>confdefs.h <<\_ACEOF +#define DEAL_II_ANON_NAMESPACE_BUG 1 +_ACEOF + + fi + rm -f conftest.1.$ac_objext conftest.2.$ac_objext conftest + + echo "$as_me:$LINENO: checking for SFINAE bug" >&5 echo $ECHO_N "checking for SFINAE bug... $ECHO_C" >&6 ac_ext=cc diff --git a/deal.II/configure.in b/deal.II/configure.in index 459139c42c..ab854ceafb 100644 --- a/deal.II/configure.in +++ b/deal.II/configure.in @@ -175,6 +175,7 @@ DEAL_II_CHECK_FUNPTR_TEMPLATE_TEMPLATE_BUG DEAL_II_CHECK_NESTED_CLASS_FRIEND_BUG DEAL_II_CHECK_MEMBER_VAR_SPECIALIZATION_BUG DEAL_II_CHECK_LONG_DOUBLE_LOOP_BUG +DEAL_II_CHECK_ANON_NAMESPACE_BUG DEAL_II_CHECK_SFINAE_BUG DEAL_II_CHECK_BOOST_SHARED_PTR_ASSIGNMENT DEAL_II_HAVE_PRETTY_FUNCTION