Scheduled Downtime
On Friday 21 April 2023 @ 5pm MT, this website will be down for maintenance and expected to return online the morning of 24 April 2023 at the latest

Compilation error with netcdf in docker container WRF 4.0

This post was from a previous version of the WRF&MPAS-A Support Forum. New replies have been disabled and if you have follow up questions related to this post, then please start a new thread from the forum home page.


New member
I'm compiling WRF inside of a docker container with Ubuntu 18.04 installed:

I'm having a problem with undefined referenced in some of the external modules. The problem appears to with where the netcdf include file is located. Please see the configuration and compilation.log files included. I also modified the source .F90 files in external/io_netcdf so that 'include' statemetns become 'include /usr/include/'. That worked for some of the files but not all. All the compiler tests from the tutorial passed prior to compiling. Any insight would be helpful. Thank you.

View attachment configure.wrf.

View attachment compilation.log
There are many errors like:
wrf_io.f:(.text+0x3ab65): undefined reference to `nf_redef_'
wrf_io.f:(.text+0x3abb1): undefined reference to `nf_put_att_text_'
wrf_io.f:(.text+0x3abd2): undefined reference to `nf_enddef_'
wrf_io.f:(.text+0x3afa1): undefined reference to `nf_put_att_text_'

This looks like your netCDF is compiled with a compiler different to the one you use to compile WRF. Please check.
Thank you @Ming Chen! I was able to successfully build WRF4.0 on Ubuntu 08.04LTS within a docker container by first installing all compilers to their latest versions and THEN building netcdf-c 4.7.0 and netcdf-f 4.4.5 from source in the Build_WRF/LIBRARIES directory (with shared libraries) as indicated in the WRF online tutorial.

Environment variables updated in ~/.bashrc:

export DIR=/root/Build_WRF/LIBRARIES
export NCDIR=/root/Build_WRF/LIBRARIES/netcdf
export NFDIR=${NCDIR}
export CC=gcc
export CXX=g++
export FC=gfortran
export FCFLAGS=-m64
export F77=gfortran
export FFLAGS=-m64
export PATH=$DIR/netcdf/bin:$PATH
export NETCDF=$DIR/netcdf

That solved this problem. One must definitely compile netcdf natively rather than use the prepackaged versions as those do not specify the compiler version used. Thanks!