Facilitate linking with libcxx
authorMark Abraham <mark.j.abraham@gmail.com>
Wed, 30 Mar 2016 03:38:46 +0000 (05:38 +0200)
committerMark Abraham <mark.j.abraham@gmail.com>
Tue, 10 May 2016 14:18:30 +0000 (16:18 +0200)
Using recent clang static analyzer versions seems to be easier with
libcxx, which we should anyway support for building and testing.

Reworked the testing for C++11 support, since it is sensible to first
test the compiler, and then the standard library. This helps users
diagnose problems. Converted this code to a function (for better
scoping), added some docs, and made the semantics clearer. Added
some explicit testing for other non-library C++11 functionality.

Introduced GMX_STDLIB_CXX_FLAGS, so that all the linked executables
can have their sources compiled with any compiler flag that might be
required. Alternatives like requiring the user to modify
CMAKE_CXX_FLAGS, or adding COMPILE_FLAGS properties to targets didn't
seem great. The latter also triggers clang to issue warnings for
source files that are still C (group kernels and TNG).

Introduced GMX_STDLIB_LIBRARIES, so that linking can proceed
correctly.

For example, the check for C++11 support needs to be passed a library
to link during the try_compile(), and the only reliable way for the
user to do that before this patch was to add the linker flag to
CMAKE_CXX_FLAGS, which then leads to clang warning about the unused
linker flag as it compiles each source file. The GMX_STDLIB_*
mechanisms probably also permit users to build against different
versions of GNU libstdc++, which may be useful on distributions like
CentOS, because CMake has no mechanism at all for this.

Updated the install guide to clarify how to choose a standard library
in the various cases. Updated the guide for using GROMACS as a library,
and the template README.

Fixed issue where the template did not have C++11 compiler flags
propagated properly. The template now builds correctly, via both
Makefile.pkg and cmake, both with normal default libstdc++ and libc++
selected via this mechanism and propagated to the installed build
system for the template.

Fixed issue where SIMD suggestion would produce a garbage suggestion
when the linking failed and OUTPUT_SIMD was left unset.

Refs #1745,#1790

Change-Id: Ieef3b47de5c1a00a203baa1b34ebf70535cf5ff0

15 files changed:
CMakeLists.txt
cmake/gmxDetectSimd.cmake
cmake/gmxTestCXX11.cmake
docs/doxygen/user/usinglibrary.md
docs/install-guide/index.rst
share/template/CMakeLists.txt
share/template/CMakeLists.txt.template
share/template/README
src/gromacs/CMakeLists.txt
src/gromacs/InstallLibInfo.cmake
src/gromacs/gromacs-config.cmake.cmakein
src/gromacs/libgromacs.pc.cmakein
src/gromacs/trajectoryanalysis/tests/CMakeLists.txt
src/programs/CMakeLists.txt
src/testutils/TestMacros.cmake

index e2216b2db80f645f2114b3c52012668cb34c370f..9676d892b0c6449295e8909c9c2ca02606b8a3d0 100644 (file)
@@ -132,6 +132,12 @@ endif()
 include(gmxDetectTargetArchitecture)
 gmx_detect_target_architecture()
 
+# Permit the user to specify a particular standard library, e.g. compiling
+# with "-stdlib=libc++" and linking with "-lc++abi -lc++" to get clang's libcxx.
+set(GMX_STDLIB_CXX_FLAGS "" CACHE STRING "Compiler flag for a C++ standard library flavour")
+set(GMX_STDLIB_LIBRARIES "" CACHE STRING "Linker libraries for a particular C++ standard library")
+mark_as_advanced(GMX_STDLIB_CXX_FLAGS)
+mark_as_advanced(GMX_STDLIB_LIBRARIES)
 
 ########################################################################
 # Detect CXX11 support and flags
@@ -152,15 +158,13 @@ include(CheckCCompilerFlag)
 include(CheckCXXCompilerFlag)
 
 # This must come early, since some of our configuration flag tests
-# depend on being able to compile C++11 source files
+# depend on being able to compile C++11 source files.
 include(gmxTestCXX11)
-gmx_test_cxx11(GMX_CXX11_SUPPORTED GMX_CXX11_FLAGS)
-if(NOT GMX_CXX11_SUPPORTED)
-message(FATAL_ERROR "This version of GROMACS requires C++11. Please use a newer compiler or use the GROMACS 5.1.x release. Note it might be sufficient to instruct the compiler to use a newer STL version. See the installation guide for details.")
-endif()
+gmx_test_cxx11(GMX_CXX11_FLAGS GMX_STDLIB_CXX_FLAGS GMX_STDLIB_LIBRARIES)
 
-# Make sure all tests are run in C++11 mode
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GMX_CXX11_FLAGS}")
+# Make sure all C++ code will be compiled in C++11 mode, with the
+# expected standard library.
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GMX_CXX11_FLAGS} ${GMX_STDLIB_CXX_FLAGS}")
 
 ########################################################################
 # User input options                                                   #
index fe7a2ca1907a60fd11b6b70605d6da6a2e7f477d..550974947d198a63c910978102bc4057af99b640 100644 (file)
@@ -68,7 +68,7 @@ function(gmx_suggest_simd _suggested_simd)
     message(STATUS "Detecting best SIMD instructions for this CPU")
 
     # Get CPU SIMD properties information
-    set(_compile_definitions "${GCC_INLINE_ASM_DEFINE} -I${CMAKE_SOURCE_DIR}/src -DGMX_CPUINFO_STANDALONE")
+    set(_compile_definitions "${GCC_INLINE_ASM_DEFINE} -I${CMAKE_SOURCE_DIR}/src -DGMX_CPUINFO_STANDALONE ${GMX_STDLIB_CXX_FLAGS}")
 
     # We need to execute the binary, so this only works if not cross-compiling.
     # However, note that we are NOT limited to x86.
@@ -77,6 +77,7 @@ function(gmx_suggest_simd _suggested_simd)
                 ${CMAKE_BINARY_DIR}
                 ${CMAKE_SOURCE_DIR}/src/gromacs/hardware/cpuinfo.cpp
                 COMPILE_DEFINITIONS ${_compile_definitions}
+                LINK_LIBRARIES ${GMX_STDLIB_LIBRARIES}
                 RUN_OUTPUT_VARIABLE OUTPUT_TMP
                 COMPILE_OUTPUT_VARIABLE GMX_CPUINFO_COMPILE_OUTPUT
                 ARGS "-features")
@@ -91,6 +92,7 @@ function(gmx_suggest_simd _suggested_simd)
             set(OUTPUT_TMP "None")
         endif(NOT GMX_CPUINFO_COMPILED)
 
+        set(OUTPUT_SIMD "None")
         if(GMX_TARGET_X86)
             if(OUTPUT_TMP MATCHES " avx512er ")
                 set(OUTPUT_SIMD "AVX_512_KNL")
index 6aa070eba9039a44b062dbbbdc2a106f48646cc3..6d1e061866fa36b71067145a269f6cc8c62ec3a2 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2012,2013,2014,2015, by the GROMACS development team, led by
+# Copyright (c) 2012,2013,2014,2015,2016, by the GROMACS development team, led by
 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
 # and including many others, as listed in the AUTHORS file in the
 # top-level source directory and at http://www.gromacs.org.
 # the research papers on the package. Check out http://www.gromacs.org.
 
 include(CheckCXXSourceCompiles)
-MACRO(GMX_TEST_CXX11 VARIABLE FLAG)
+
+# Check whether both a suitable C++11-compatible compiler and standard
+# library is available, and give a fatal error if not.
+#
+# Any required compiler flag for C++11 support is returned in
+# ${FLAG}. The other parameters are only inputs, naming variables that
+# contain flags that may have been detected, or set by the user.
+function(GMX_TEST_CXX11 CXX11_CXX_FLAG_NAME STDLIB_CXX_FLAG_NAME STDLIB_LIBRARIES_NAME)
+
+    # First check that the compiler is OK, and find the appropriate flag.
+
     if(WIN32 AND NOT MINGW)
-        set(CXX11_FLAG "/Qstd=c++0x")
+        set(CXX11_CXX_FLAG "/Qstd=c++0x")
     elseif(CYGWIN)
-        set(CXX11_FLAG "-std=gnu++0x") #required for strdup
+        set(CXX11_CXX_FLAG "-std=gnu++0x") #required for strdup
     else()
-        set(CXX11_FLAG "-std=c++0x")
+        set(CXX11_CXX_FLAG "-std=c++0x")
     endif()
-    CHECK_CXX_COMPILER_FLAG("${CXX11_FLAG}" CXXFLAG_STD_CXX0X)
+    CHECK_CXX_COMPILER_FLAG("${CXX11_CXX_FLAG}" CXXFLAG_STD_CXX0X)
     if(NOT CXXFLAG_STD_CXX0X)
-        set(CXX11_FLAG "")
+        set(CXX11_CXX_FLAG "")
+    endif()
+    set(CMAKE_REQUIRED_FLAGS "${CXX11_CXX_FLAG}")
+    check_cxx_source_compiles(
+"struct a {
+  explicit operator bool() {return true;}
+  a() {};
+  a(a&&) = default;
+  a(const a&) = delete;
+};
+class b: public a {};
+b f() {
+  return b();
+}
+constexpr int factorial(int n)
+{
+    return n <= 1? 1 : (n * factorial(n - 1));
+}
+void checkRvalueReference(int &&);
+template <typename T> void someFunction();
+extern template void someFunction<int>();
+int main() {
+  double *x = nullptr;
+  int array[5] = { 1, 2, 3, 4, 5 };
+  for (int& x : array)
+    x *= 2;
+}" CXX11_SUPPORTED)
+    if(CXX11_SUPPORTED)
+        set(${CXX11_CXX_FLAG_NAME} ${CXX11_CXX_FLAG} PARENT_SCOPE)
+    else()
+        message(FATAL_ERROR "This version of GROMACS requires a C++11 compiler. Please use a newer compiler or use the GROMACS 5.1.x release. See the installation guide for details.")
     endif()
-    set(CMAKE_REQUIRED_FLAGS "${CXX11_FLAG}")
+
+    # Now check the standard library is OK
+
+    set(CMAKE_REQUIRED_FLAGS "${CXX11_CXX_FLAG} ${${STDLIB_CXX_FLAG_NAME}}")
+    set(CMAKE_REQUIRED_LIBRARIES "${${STDLIB_LIBRARIES_NAME}}")
     check_cxx_source_compiles(
 "#include <map>
 #include <memory>
 #include <utility>
-class a { explicit operator bool() {return true;} };
 int main() {
   typedef std::unique_ptr<int> intPointer;
   intPointer p(new int(10));
   std::map<int, std::unique_ptr<int>> m;
   m.insert(std::make_pair(5, std::move(p)));
-}" ${VARIABLE})
-    set(CMAKE_REQUIRED_FLAGS "")
-    if(${VARIABLE})
-        set(${FLAG} ${CXX11_FLAG})
+}" CXX11_STDLIB_PRESENT)
+    if(NOT CXX11_STDLIB_PRESENT)
+        message(FATAL_ERROR "This version of GROMACS requires C++11-compatible standard library. Please use a newer compiler, or a newer standard library, or use the GROMACS 5.1.x release. See the installation guide for details.")
     endif()
-ENDMACRO()
+endfunction()
index ba677507033b34da55ece342b150929706fa3265..5139279f0c90d4ceb8242e3a7b575534c8a6efbb 100644 (file)
@@ -169,6 +169,9 @@ Under the hood, this uses imported CMake targets to represent `libgromacs`.</dd>
 compile the \Gromacs headers.</dd>
 <dt>`GROMACS_IS_DOUBLE`</dt>
 <dd>Whether the found \Gromacs was compiled in double precision.</dd>
+<dt>`GROMACS_CXX_FLAGS`</dt>
+<dd>Required compiler flags, e.g. for compiling in C++11 mode,
+or selecting the standard library flavour.</dd>
 </dl>
 
 Declared macros/functions that can be used for checking for correctness of some
index debfb5744e99b659cf59f5a3217d77845a42b33f..41cc9137966c10f05eed91aa54dd57420cdb4535 100644 (file)
@@ -96,22 +96,26 @@ Getting good performance on an OS and architecture requires choosing a
 good compiler. In practice, many compilers struggle to do a good job
 optimizing the |Gromacs| architecture-optimized SIMD kernels.
 
-C++11 support requires both support in the compiler as well as in the
-C++ library. Multiple compilers do not provide their own library
-but use the system library. It is required to select a library with
-sufficient C++11 support. Both the Intel and clang compiler on Linux use
-the libstdc++ which comes with gcc as the default C++ library. 4.6.1 of
-that library is required. Also the C++ library version has to be
-supported by the compiler. To select the C++ library version use:
-
-* For Intel: ``CXXFLAGS=-gcc-name=/path/to/gcc/binary`` or make sure
+C++11 support requires adequate support in both the compiler and the
+C++ library. The gcc compiler includes its own GNU standard library
+called libstdc++, which just works. Both the Intel and clang compiler
+on Linux use the libstdc++ which comes with gcc as the default C++
+library. Version 4.6.1 of that library is required to have enough
+language support for |Gromacs|, and the C++ library version must be
+supported by the compiler. To select a particular libstdc++ library,
+use:
+
+* For Intel: ``-DGMX_STDLIB_CXX_FLAGS=-gcc-name=/path/to/gcc/binary`` or make sure
   that the correct gcc version is first in path (e.g. by loading the gcc
   module)
-* For clang: ``CFLAGS=--gcc-toolchain=/path/to/gcc/folder
-  CXXFLAGS=--gcc-toolchain=/path/to/gcc/folder``. This folder should
+* For clang: ``-DCMAKE_CXX_FLAGS=--gcc-toolchain=/path/to/gcc/folder``. This folder should
   contain ``include/c++``.
-* On Windows with e.g. Intel: at least MSVC 2015 is required. Load the
-  enviroment with vcvarsall.bat.
+
+On Windows with e.g. Intel, the MSVC standard library is used, and at
+least MSVC 2015 is required. Load the enviroment with vcvarsall.bat.
+
+To build with clang's libcxx standard library, use
+``-DGMX_STDLIB_CXX_FLAGS=-stdlib=libc++ -DGMX_STDLIB_LIBRARIES='-lc++abi -lc++'``.
 
 For best performance, the |Gromacs| team strongly recommends you get the
 most recent version of your preferred compiler for your platform.
index 29ef88ad49f8670a5ff6bf8f6c333cb91fbf71f4..17a6dccade45f83351904c51a43286761d1d4def 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2011,2012,2014, by the GROMACS development team, led by
+# Copyright (c) 2011,2012,2014,2016, by the GROMACS development team, led by
 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
 # and including many others, as listed in the AUTHORS file in the
 # top-level source directory and at http://www.gromacs.org.
@@ -33,7 +33,7 @@
 # the research papers on the package. Check out http://www.gromacs.org.
 
 add_executable(template template.cpp)
-target_link_libraries(template libgromacs ${GMX_EXE_LINKER_FLAGS})
+target_link_libraries(template libgromacs ${GMX_EXE_LINKER_FLAGS} ${GMX_STDLIB_LIBRARIES})
 install(FILES CMakeLists.txt.template
         DESTINATION ${DATA_INSTALL_DIR}/template
         RENAME CMakeLists.txt
index 5d738b8d637554aa696d99ceb2da686d71427f05..6720381b35328b8e05ab8962a5897f6547aab4cf 100644 (file)
@@ -39,4 +39,6 @@ if (CMAKE_GENERATOR MATCHES "Visual Studio")
 endif()
 
 add_executable(template template.cpp)
+set_target_properties(template PROPERTIES
+                      COMPILE_FLAGS "${GROMACS_CXX_FLAGS}")
 target_link_libraries(template ${GROMACS_LIBRARIES})
index ae27f37a84218d2b430c310951c75df5524a08d8..0a75e9b6029b39a72ff59f6c7a481449ba92cac0 100644 (file)
@@ -18,13 +18,13 @@ makes use of pkg-config to build the template program:
 $ source /path/to/GMXRC
 $ make -f Makefile.pkg
 
-You will need to make sure that you use a sufficiently similar C++
-compiler and C++ Standard Library as the one that was used for
-compiling GROMACS, preferably the same one.
+You will need to make sure that you use the same C++ compiler
+and C++ Standard Library as the one that was used for compiling
+GROMACS.
 See the Doxygen documentation for using GROMACS as a library for
 more details about the build system used to build the template, as
 well as its limitations (link to the latest development version):
-  <http://jenkins.gromacs.org/job/Documentation_Gerrit_Nightly/javadoc/doxygen/html-user/page_usinglibrary.xhtml>
+  <http://jenkins.gromacs.org/job/Documentation_Nightly_master/javadoc/doxygen/html-user/page_usinglibrary.xhtml>
 
 ----------------------------------------------------------
 
index e0dde082535ba801b3b2a9ffddd1b7b9d0f424e2..edc051fe8328dcb0f2ff5604048c6e1a07bc66b1 100644 (file)
@@ -205,7 +205,8 @@ target_link_libraries(libgromacs
                       ${TNG_IO_LIBRARIES}
                       ${FFT_LIBRARIES} ${LINEAR_ALGEBRA_LIBRARIES}
                       ${XML_LIBRARIES}
-                      ${THREAD_LIB} ${GMX_SHARED_LINKER_FLAGS} ${OPENCL_LIBRARIES})
+                      ${THREAD_LIB} ${GMX_SHARED_LINKER_FLAGS} ${OPENCL_LIBRARIES}
+                      ${GMX_STDLIB_LIBRARIES})
 set_target_properties(libgromacs PROPERTIES
                       OUTPUT_NAME "gromacs${GMX_LIBS_SUFFIX}"
                       SOVERSION ${LIBRARY_SOVERSION_MAJOR}
index 58856f88ce4b807452fbb5df5ec270d6a94c0bee..ccc12719caa320a661366888750b6fd7a7383d84 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2014, by the GROMACS development team, led by
+# Copyright (c) 2014,2016, by the GROMACS development team, led by
 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
 # and including many others, as listed in the AUTHORS file in the
 # top-level source directory and at http://www.gromacs.org.
@@ -46,7 +46,7 @@ function (do_pkgconfig)
             set(PKG_CFLAGS "${PKG_CFLAGS} ${_def}")
         endforeach()
     endif()
-    set(PKG_CFLAGS "${PKG_CFLAGS} ${OpenMP_C_FLAGS}")
+    set(PKG_CFLAGS "${PKG_CFLAGS} ${OpenMP_C_FLAGS} ${GMX_CXX11_FLAGS} ${GMX_STDLIB_CXX_FLAGS}")
 
     configure_file(libgromacs.pc.cmakein
                    libgromacs.pc @ONLY)
index c7dfb0d8f7d4ecd23c265875adbaa599f1fcfda7..77a50db495d3ff9460fe99611b9eb77fc1099b6e 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2014, by the GROMACS development team, led by
+# Copyright (c) 2014,2016, by the GROMACS development team, led by
 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
 # and including many others, as listed in the AUTHORS file in the
 # top-level source directory and at http://www.gromacs.org.
@@ -66,7 +66,7 @@ foreach (_dir ${_include_dirs})
         list(APPEND GROMACS_INCLUDE_DIRS ${_gmx_root_dir}/${_dir})
     endif()
 endforeach()
-set(GROMACS_LIBRARIES libgromacs)
+set(GROMACS_LIBRARIES libgromacs @GMX_STDLIB_LIBRARIES@)
 set(GROMACS_DEFINITIONS @INSTALLED_HEADER_DEFINITIONS@)
 set(GROMACS_IS_DOUBLE @GMX_DOUBLE@)
 if (DEFINED GROMACS_SUFFIX AND NOT "${GROMACS_SUFFIX}" STREQUAL "@GMX_LIBS_SUFFIX@")
@@ -76,6 +76,7 @@ set(GROMACS_SUFFIX "@GMX_LIBS_SUFFIX@")
 set(GROMACS_CXX_COMPILER "@GROMACS_CXX_COMPILER@")
 set(GROMACS_CXX_COMPILER_ID "@CMAKE_CXX_COMPILER_ID@")
 set(GROMACS_CXX_COMPILER_VERSION "@CMAKE_CXX_COMPILER_VERSION@")
+set(GROMACS_CXX_FLAGS "@GMX_CXX11_FLAGS@ @GMX_STDLIB_CXX_FLAGS@")
 
 # Produce a message, since find_package() prints nothing on success.
 include(FindPackageMessage)
@@ -122,8 +123,8 @@ function (gromacs_check_compiler LANG)
         NOT "${CMAKE_${LANG}_COMPILER_ID}" STREQUAL "${GROMACS_${LANG}_COMPILER_ID}" OR
         NOT "${CMAKE_${LANG}_COMPILER_VERSION}" STREQUAL "${GROMACS_${LANG}_COMPILER_VERSION}")
         message(WARNING
-            "You are compiling with a different C++ compiler than what was used "
-            "to compile GROMACS. This may lead to linking or runtime problems. "
+            "You are compiling with a different C++ compiler from the one that was "
+            "used to compile GROMACS. This may lead to linking or runtime problems. "
             "GROMACS was compiled with "
             "${GROMACS_${LANG}_COMPILER_ID} ${GROMACS_${LANG}_COMPILER_VERSION} "
             "(${GROMACS_${LANG}_COMPILER}).")
index a3dc979e09b53dbd28eb747c59a46078309351f4..228845ea851f409141db4fff1a54405af7e83310 100644 (file)
@@ -6,6 +6,6 @@ URL: http://www.gromacs.org
 Version: @GMX_VERSION_STRING@
 Requires: @PKG_FFT@ @PKG_XML@
 Libs.private: @CMAKE_THREAD_LIBS_INIT@ @PKG_DL_LIBS@ @OpenMP_LINKER_FLAGS@
-Libs: -L${libdir} -lgromacs@GMX_LIBS_SUFFIX@ @PKG_FFT_LIBS@ -lm
+Libs: -L${libdir} -lgromacs@GMX_LIBS_SUFFIX@ @PKG_FFT_LIBS@ -lm @GMX_STDLIB_LIBRARIES@
 Cflags: @PKG_CFLAGS@
 
index 9a7eb5f7aefe8887cf20922f86753dcdc38b3960..b59d79fd980c1f8395c7fc1de09c19856b64219b 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2010,2012,2013,2014,2015, by the GROMACS development team, led by
+# Copyright (c) 2010,2012,2013,2014,2015,2016, by the GROMACS development team, led by
 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
 # and including many others, as listed in the AUTHORS file in the
 # top-level source directory and at http://www.gromacs.org.
@@ -46,4 +46,4 @@ gmx_add_unit_test(TrajectoryAnalysisUnitTests trajectoryanalysis-test
                   $<TARGET_OBJECTS:analysisdata-test-shared>)
 
 add_executable(test_selection ${UNITTEST_TARGET_OPTIONS} test_selection.cpp)
-target_link_libraries(test_selection libgromacs ${GMX_EXE_LINKER_FLAGS})
+target_link_libraries(test_selection libgromacs ${GMX_EXE_LINKER_FLAGS} ${GMX_STDLIB_LIBRARIES})
index 64cd31b1d4063dccf205fe499333a4f480a70cdd..16590b6d18b30e2869aa3f535b326c7ebde50619 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
+# Copyright (c) 2010,2011,2012,2013,2014,2015,2016, by the GROMACS development team, led by
 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
 # and including many others, as listed in the AUTHORS file in the
 # top-level source directory and at http://www.gromacs.org.
@@ -43,7 +43,7 @@ if(GMX_FAHCORE)
     add_library(fahcore $<TARGET_OBJECTS:mdrun_objlib>)
 elseif(GMX_BUILD_MDRUN_ONLY)
     add_executable(mdrun $<TARGET_OBJECTS:mdrun_objlib> mdrun_main.cpp)
-    target_link_libraries(mdrun libgromacs ${GMX_EXE_LINKER_FLAGS})
+    target_link_libraries(mdrun libgromacs ${GMX_EXE_LINKER_FLAGS} ${GMX_STDLIB_LIBRARIES})
     set(BINARY_NAME "mdrun${GMX_BINARY_SUFFIX}")
     set_target_properties(mdrun PROPERTIES
         OUTPUT_NAME "${BINARY_NAME}"
@@ -65,7 +65,7 @@ else()
         ${GMX_MAIN_SOURCES}
         $<TARGET_OBJECTS:mdrun_objlib>
         $<TARGET_OBJECTS:view_objlib>)
-    target_link_libraries(gmx libgromacs ${GMX_EXE_LINKER_FLAGS})
+    target_link_libraries(gmx libgromacs ${GMX_EXE_LINKER_FLAGS} ${GMX_STDLIB_LIBRARIES})
     if(GMX_X11)
         target_link_libraries(gmx ${X11_LIBRARIES})
     endif()
index b84fa4e4c2fb3e0ec43716e28a1bb35d0b61c781..faff8af3d290a8416d7635334253bbfd31806762 100644 (file)
@@ -71,7 +71,7 @@ function (gmx_add_gtest_executable EXENAME)
         add_executable(${EXENAME} ${UNITTEST_TARGET_OPTIONS}
             ${_source_files} ${TESTUTILS_DIR}/unittest_main.cpp)
         target_link_libraries(${EXENAME}
-            ${TESTUTILS_LIBS} libgromacs ${GMOCK_LIBRARIES} ${GMX_EXE_LINKER_FLAGS})
+            ${TESTUTILS_LIBS} libgromacs ${GMOCK_LIBRARIES} ${GMX_EXE_LINKER_FLAGS} ${GMX_STDLIB_LIBRARIES})
         set_property(TARGET ${EXENAME}
             APPEND PROPERTY COMPILE_FLAGS "${GMOCK_COMPILE_FLAGS}")
         set_property(TARGET ${EXENAME}
@@ -100,7 +100,7 @@ function (gmx_register_integration_test NAME EXENAME)
 
         # GMX_EXTRA_LIBRARIES might be needed for mdrun integration tests at
         # some point.
-        # target_link_libraries(${EXENAME} ${GMX_EXTRA_LIBRARIES})
+        # target_link_libraries(${EXENAME} ${GMX_EXTRA_LIBRARIES} ${GMX_STDLIB_LIBRARIES})
     endif()
 endfunction ()
 
@@ -144,7 +144,7 @@ function (gmx_register_mpi_integration_test NAME EXENAME NUMPROC)
 
             # GMX_EXTRA_LIBRARIES might be needed for mdrun integration tests at
             # some point.
-            # target_link_libraries(${EXENAME} ${GMX_EXTRA_LIBRARIES})
+            # target_link_libraries(${EXENAME} ${GMX_EXTRA_LIBRARIES} ${GMX_STDLIB_LIBRARIES})
         elseif(GMX_THREAD_MPI)
             add_test(NAME ${NAME}
                 COMMAND
@@ -156,7 +156,7 @@ function (gmx_register_mpi_integration_test NAME EXENAME NUMPROC)
 
             # GMX_EXTRA_LIBRARIES might be needed for mdrun integration tests at
             # some point.
-            # target_link_libraries(${EXENAME} ${GMX_EXTRA_LIBRARIES})
+            # target_link_libraries(${EXENAME} ${GMX_EXTRA_LIBRARIES} ${GMX_STDLIB_LIBRARIES})
         endif()
     endif()
 endfunction ()