Problems linking Fortran code with 3.3.1 shared library (w/ CMake)

Description

I was unable to get the CGNS 3.3.1 shared library to successfully link/compile with my Fortran code, but the static library works fine. In my code, I use the character array BCTypeName defined in the CGNS module and the compiler aborts compilation giving the error:
undefined reference to `cgns_mp_bctypename_'

A simple code to test this problem is
program test_cgns
use cgns
implicit none
integer :: i
do i = 1,size(bctypename)
write (,) trim(adjustl(bctypename))
end do
end program test_cgns

I think the problem is because the object file created from compiling cgns_f.F90 is not being added to the shared library.

I was able to fix this issue and successfully link to the shared library by making the following change to the file CGNS-3.3.1/src/CMakeLists.txt.

I changed line 514 from
add_library(cgns_shared SHARED ${cgns_FILES})
to
if (CGNS_ENABLE_FORTRAN)
add_library(cgns_shared SHARED ${cgns_FILES} cgns_f.F90)
else (CGNS_ENABLE_FORTRAN)
add_library(cgns_shared SHARED ${cgns_FILES})
endif (CGNS_ENABLE_FORTRAN)

This change was inspired by the similar conditional statement for the static library on line 504. I have essentially zero experience with CMake code so is probably a more elegant way to fix this problem.

Environment

Red Hat Enterprise Linux 6.5, HDF5 1.8.17 (with SZip 2.1), Intel 2017 Update 2, Intel MPI. I didn't try building with GCC or another compiler because it would require recompiling too many library dependencies.

Assignee

Scot Breitenfeld

Reporter

Anonymous

Components

Fix versions

Affects versions

Priority

Blocker
Configure