diff --git a/install/DEFAULTS.inc b/install/DEFAULTS.inc index ec7793b67..dc59400c6 100644 --- a/install/DEFAULTS.inc +++ b/install/DEFAULTS.inc @@ -520,6 +520,18 @@ else endif endif +# Embed the netcdf library directories in the executables. Without this the +# codes link against $(NETCDFDIR) but resolve at run time against whatever the +# loader finds first, which fails with e.g. +# symbol lookup error: undefined symbol: netcdf_mp_nf90_create_ +# when a system netcdf shadows the bundled one, and silently mixes libraries +# when the two were built by different compilers. +NETCDF_RPATH = -Wl,-rpath,$(NETCDFDIR) +ifneq ($(NETCDF_C_DIR),$(NETCDFDIR)) + NETCDF_RPATH += -Wl,-rpath,$(NETCDF_C_DIR) +endif +NETCDF_EXTRA_LIBS += $(NETCDF_RPATH) + # Intel specifics #---------------- # include compiler specific libs for intel fast moves diff --git a/install/TARGETS.inc b/install/TARGETS.inc index b596e8c0a..0cbc65125 100644 --- a/install/TARGETS.inc +++ b/install/TARGETS.inc @@ -43,8 +43,9 @@ netcdf-c: v hdf5 cd ../; git submodule update --init deps/src/netcdf-c; if [ ! -f ../deps/src/netcdf-c/Makefile ]; then \ cd ../deps/src/netcdf-c; \ + CC="$(CC)" FC="$(FC)" F77="$(FC)" \ CPPFLAGS="-I$(realpath $(DEPSINSTALLDIR))/include" \ - LDFLAGS="-L$(realpath $(DEPSINSTALLDIR))/lib" \ + LDFLAGS="-L$(realpath $(DEPSINSTALLDIR))/lib -Wl,-rpath,$(realpath $(DEPSINSTALLDIR))/lib" \ ./configure --prefix=$(realpath $(DEPSINSTALLDIR)); \ fi cd ../deps/src/netcdf-c; \ @@ -56,8 +57,9 @@ netcdf-fortran: v netcdf-c cd ../; git submodule update --init deps/src/netcdf-fortran; if [ ! -f ../deps/src/netcdf-fortran/Makefile ]; then \ cd ../deps/src/netcdf-fortran; \ + CC="$(CC)" FC="$(FC)" F77="$(FC)" \ CPPFLAGS="-I$(realpath $(DEPSINSTALLDIR))/include" \ - LDFLAGS="-L$(realpath $(DEPSINSTALLDIR))/lib" \ + LDFLAGS="-L$(realpath $(DEPSINSTALLDIR))/lib -Wl,-rpath,$(realpath $(DEPSINSTALLDIR))/lib" \ ./configure --prefix=$(realpath $(DEPSINSTALLDIR)); \ fi cd ../deps/src/netcdf-fortran; \ @@ -69,6 +71,8 @@ hdf5: v cd ../; git submodule update --init deps/src/hdf5; if [ ! -f ../deps/src/hdf5/Makefile ]; then \ cd ../deps/src/hdf5; \ + CC="$(CC)" FC="$(FC)" \ + LDFLAGS="-Wl,-rpath,$(realpath $(DEPSINSTALLDIR))/lib" \ ./configure --prefix=$(realpath $(DEPSINSTALLDIR)); \ fi cd ../deps/src/hdf5; \ diff --git a/install/makefile b/install/makefile index 056de2ab6..f1912b8ef 100644 --- a/install/makefile +++ b/install/makefile @@ -116,6 +116,22 @@ realclean: clean clear # only for regenerating it when source USE/MODULE relationships change, and # require python3 (used by maintainers and the CI deps job, not end users). PYTHON ?= python3 +# Remove the autotools configuration of the bundled dependencies. The netcdf +# and hdf5 rules only run ./configure when no Makefile is present, so a plain +# `clean` keeps whatever toolchain configured them first. Switching FC/CC +# without this leaves gfortran-built module files in place, and the codes then +# fail with a confusing "module file was not generated by any release of this +# compiler" followed by cascading kind-parameter errors. +.PHONY: depsclean +depsclean: + for d in hdf5 netcdf-c netcdf-fortran; do \ + if [ -f ../deps/src/$$d/Makefile ]; then \ + (cd ../deps/src/$$d && $(MAKE) distclean >/dev/null 2>&1 || true); \ + fi; \ + rm -f ../deps/src/$$d/Makefile ../deps/src/$$d/config.cache; \ + done + rm -rf ../deps/lib/* ../deps/include/* ../deps/bin/* ../deps/share ../deps/hdf5 + .PHONY: deps checkdeps deps: $(PYTHON) gen_deps.py > DEPENDENCIES.inc