[CMake] cmake FortranCInterface test fails in a linking step due to the -rdynamic option in Linux-GNU.cmake

Bob Walkup walkup at us.ibm.com
Thu Jan 8 12:44:35 EST 2015



I am attempting to build an application that uses cmake, but encountered an
issue that is present in the most recent cmake versions.  The system is
Linux, and the problem occurs with a FortranCInterface test, when the
Fortran compiler is IBM XL Fortran (the problem does not arise with
gfortran).  The project's CMakeLists.txt file contains :

include(FortranCInterface)
...
FortranCInterface_VERIFY(CXX)
...

With the XL Fortran compiler, the command that fails is :

/opt/ibmcmp/xlf/15.1.1/bin/xlf90_r
CMakeFiles/FortranCInterface.dir/main.F.o
CMakeFiles/FortranCInterface.dir/call_sub.f.o
CMakeFiles/FortranCInterface.dir/call_mod.f90.o  -o FortranCInterface
-rdynamic libsymbols.a libmyfort.a
***/opt/ibm/xlf/15.1.1/bin/.orig/xlf90_r: 1501-210 (S) command option
ynamic contains an incorrect subargument***

The "-rdynamic" option is added by the cmake infrastructure via the file "
Modules/Platform/Linux-GNU.cmake ", which contains :

set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-rdynamic")

I think it would be preferable to replace "-rdynamic" with
"-Wl,-export-dynamic" as follows:

set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-Wl,-export-dynamic")

in the Linux-GNU.cmake file that is provided by cmake.

I should mention that the system is Linux and that GNU compilers are used
for C and C++.  The problem is that the cmake infrastructure adds the
"-rdynamic" option when the XL Fortran compiler script is used as the
linker during the FortranCInterface test, but "-rdynamic" is an option that
is specific to the GNU compiler set, and the "-r" conflicts with an XL
Fortran compiler option, resulting in a linking failure.  However,
"-rdynamic" is fully equivalent to "-Wl,-export-dynamic", which explicitly
passes the correct option to the GNU ld command (this is Linux), avoiding
any such conflicts.

I tried some other approaches including adding lines like these to the
project's CMakeLists.txt file, without success :

set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "-Wl,-export-dynamic")
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-Wl,-export-dynamic")
set(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS "-Wl,-export-dynamic")

The "-rdynamic" option listed in the Linux-GNU.cmake file still got into
the linking script and caused linking to fail.  The only way that I found
to work around the problem was to edit the Linux-GNU.cmake file in the
cmake install path and replace "-rdynamic" with "-Wl.-export-dynamic", as
indicated above.  I believe that replacing "-rdynamic" with
"-Wl,-export-dynamic" is generally valid on Linux systems, and is clearly
preferable.  If there are other ways to address this issue, I would like to
learn about them.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150108/49957a9f/attachment.html>


More information about the CMake mailing list