Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct issues with netCDF library linking and loading in mesh_tools/grid_rotate #556

Merged
merged 2 commits into from
Feb 29, 2024

Conversation

mgduda
Copy link
Collaborator

@mgduda mgduda commented Feb 27, 2024

This PR makes changes to the Makefile for the grid_rotate tool to address issues with netCDF library linking and loading.

Prior to this PR, the grid_rotate program's Makefile assumed that the output of nf-config --flibs was sufficient to provide all library linking flags related to the netCDF library. In netCDF-Fortran 4.6.1, however, the nf-config --flibs output includes the netCDF-C library (-lnetcdf), but it does not include the library search path for this library, leading to compilation errors like

      ld: cannot find -lnetcdf
      ld: cannot find -lnetcdf

As a workaround, this PR adds -L$(shell nc-config --libdir) to the definition of FCLIBS in the Makefile.

Even after addressing linking errors, on systems that provide netCDF shared libraries, it was in some cases still necessary
to manually set the LD_LIBRARY_PATH environment variable to ensure that the netCDF libraries could be found by the loader. To work around this issue, the Makefile now tries to extract linker rpath flags from the output of nf-config --flibs and nc-config --libs. These flags are stored in the RPATH_FLAGS make variable, which is then appended to the FCLIBS variable. With the search paths for the netCDF shared libraries included in the grid_rotate executable, it should no longer be necessary to manipulate the LD_LIBRARY_PATH environment variable.

…tran 4.6.1

In netCDF-Fortran 4.6.1 (at least, as installed on NCAR's Derecho system), the
`nf-config --flibs` output includes the netCDF-C library (-lnetcdf), but it does
not include the library search path for this library, leading to compilation
errors like

  ld: cannot find -lnetcdf
  ld: cannot find -lnetcdf

As a workaround, this commit adds "-L$(shell nc-config --libdir)" to the
definition of FCLIBS in the grid_rotate Makefile.
…rpath

On NCAR's Derecho system, compiler wrappers generally handle the setting of
rpath for shared libraries in compiled executables. However, the Fortran
compiler used in the grid_rotate Makefile is set to the actual compiler used to
build the netCDF library using `nf-config --fc`, thereby precluding the use of
the compiler wrapper. This leads to runtime issues in locating the netCDF shared
libraries, e.g.,

  ./convert_mpas: error while loading shared libraries: libnetcdff.so.7: cannot open shared object file: No such file or directory

As a workaround, the grid_rotate Makefile now tries to extract linker rpath
flags from the output of `nf-config --flibs` and `nc-config --libs`. These flags
are stored in the RPATH_FLAGS make variable, which is then appended to the
FCLIBS variable.
@mgduda mgduda force-pushed the grid_rotate/netcdf_shared_lib_fix branch from bff9461 to 4223b42 Compare February 27, 2024 23:43
@mgduda mgduda requested a review from gdicker1 February 28, 2024 18:55
Copy link
Collaborator

@gdicker1 gdicker1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a few builds on Derecho (to look at different compilers and software-stacks there) and they all succeeded. Looks good to me!

@mgduda mgduda merged commit 2070522 into MPAS-Dev:master Feb 29, 2024
7 checks passed
@mgduda mgduda deleted the grid_rotate/netcdf_shared_lib_fix branch February 29, 2024 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants