Project

Profile

Help

HostedRedmine.com has moved to the Planio platform. All logins and passwords remained the same. All users will be able to login and use Redmine just as before. Read more...

Feature #364235

static linkage: HALMD_USE_STATIC_LIBS and CMAKE_EXE_LINKER_FLAGS

Added by Felix Höfling over 6 years ago. Updated over 6 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Sprint/Milestone:
-
Start date:
Due date:
% Done:

0%

Estimated time:

Description

The CMake variable HALMD_USE_STATIC_LIBS is cached, but changing it for a later CMake run to "ON" has not the desired effect. It is expected that HALMD_USE_STATIC_LIBS=TRUE results in a binary without any shared library dependencies (except for libcudart).

If HALMD_USE_STATIC_LIBS is toggled then prerequisites (Boost, HDF5, Lua) are searched again for static versions, but CMAKE_EXE_LINKER_FLAGS has "-static-libstdc++ -static-libgcc" only if static linking was enabled at the
first run of CMake. However, toggling HALMD_USE_STATIC_LIBS and removing CMAKE_EXE_LINKER_FLAGS (in ccmake) has an effect on linkage.

The additional linker flags are inherited from CMAKE_EXE_LINKER_FLAGS_INIT, set in cmake/platform.cmake. However, the GCC manual suggests that only -static-libstc++ is to be used (g++ may even ignore -static-libgcc):

If a library or main executable is supposed to throw or catch exceptions, you must link it [...] with the shared libgcc.

History

#1 Updated by Nicolas Höft over 6 years ago

One relevant bug report is here:
https://www.cmake.org/Bug/view.php?id=13439&history=1
So, for Boost one has to add these lines:
unset(Boost_INCLUDE_DIR CACHE)
unset(Boost_LIBRARY_DIRS CACHE)

should be similar in HDF5 and Lua

#2 Updated by Felix Höfling over 6 years ago

The Boost library, etc., are searched after the STATIC_LIBS switch is
evaluated, which sets Boost_USE_STATIC_LIBS. According to my tests, the
switch works here: toggling the flag in ccmake and re-generating flips
between static and dynamic libraries.

The example in the supposed CMake bug is a bit academic as it contains
multiple calls to find_package.

Also available in: Atom PDF