[MITgcm-support] Recommended NetCDF libraries

Roland Young Roland.Young at physics.ox.ac.uk
Tue Apr 14 07:11:10 EDT 2015


Hi Jonny,

I had this exact error and was able to fix it. It was a little while ago so the fix may not be quite as I remember. 

Anyway, I started to get those "undefined reference to `nf_create_” type errors immediately after NetCDF v4 had been installed on my system. v4 and pre-v4 use differently formatted include files as far as I can tell, and the C preprocessor was trying to use the wrong one. The C preprocessor searches several default directories for include files. In my case it searches /usr/local/include first followed by some others, including /usr/include. Now the NetCDF file you need (netcdf.inc), which defines those variables you list, was in /usr/include but the new version (with the same filename, but wrong declarations) had been put in /usr/local/include, so cpp was finding and using that first.

You can force a particular folder to the top of the list of default folders that CPP searches by adding the following flag to CPP:

-isystem <folder>

(you can force cpp to search custom folders first with another option but if the folder you add is already in the default list cpp will ignore that option)

To get this to work in the MITgcm compilation, I had to add the following line to my MITgcm/tools/build_options/ machine file:

INC_OVERWRITE=“-isystem /usr/include”

to get the right directory, and then I had to edit genmake2 and xmakedepend to get the compilation scripts to recognise and use this option. Running diff on my new and original files I get the output below, which you should be able to apply to your scripts with the patch command. These basically just pass my overwrite option through the scripts correctly to make sure they are added to the cpp calls in the Makefile.

I expect there is a simpler way to do this but it seemed to work for me.

What is weird is that I’ve run this on other machines which only have v4 NetCDF libraries and it seems to work fine - if it ain’t broke, don’t look too closely…

Let me know if it works.

Best wishes,

Roland



--- genmake2.orig	2015-03-10 12:37:08.610641646 +0000
+++ genmake2	2015-03-10 14:30:43.581113027 +0000
@@ -1278,6 +1278,7 @@
GSL=
DEVEL=
HAVE_TEST_L=
+INC_OVERWRITE=

# set this to "t" to enable lapack test
CHECK_FOR_LAPACK=f
@@ -2955,7 +2956,7 @@

depend:
	@\$(MAKE) -f \$(MAKEFILE) links
-	\$(MAKEDEPEND) -f \$(MAKEFILE) -o .$FS \$(DEFINES) \$(INCLUDES) \$(CPPINCLUDES) \$(F77_SRC_FILES)
+	\$(MAKEDEPEND) -f \$(MAKEFILE) -o .$FS $INC_OVERWRITE \$(DEFINES) \$(INCLUDES) \$(CPPINCLUDES) \$(F77_SRC_FILES)
	\$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
	-rm -f makedepend.out

@@ -3053,7 +3054,7 @@
## %.o : %.F

# C preprocessing and replacing the _d in constants:
-CPPCMD = cat \$< | ${CPP} \$(DEFINES) \$(INCLUDES) | ${S64}
+CPPCMD = cat \$< | ${CPP} $INC_OVERWRITE \$(DEFINES) \$(INCLUDES) | ${S64}

.F.$FS:
	\$(CPPCMD)  > \$@
@@ -3319,7 +3320,7 @@

.PHONY: adDepend
adDepend: \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) \$(addsuffix _mod.FF90, \$(CB2M_F90_SRC_NAMES)) \$(F77_SRC_FILES:.F=_cb2m.FF90)
-	\$(MAKEDEPEND) -f \$(MAKEFILE) -o .$FS \$(DEFINES) \$(INCLUDES) \$(F77_SRC_FILES)
+	\$(MAKEDEPEND) -f \$(MAKEFILE) -o .$FS $INC_OVERWRITE \$(DEFINES) \$(F77_SRC_FILES)
	\$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
	-rm -f makedepend.out




--- xmakedepend.orig	2015-03-10 12:58:49.774383594 +0000
+++ xmakedepend	2015-03-10 13:27:14.303975347 +0000
@@ -142,6 +142,11 @@
			    shift
			    ;;

+         -isystem)
+             echo $n "-isystem $2 $c" >> $ARGS
+             shift
+             ;;
+
			-*)
			    echo "Unknown option '$1' ignored" 1>&2
			    ;;







More information about the MITgcm-support mailing list