# MEGANv3.1 processing compilation

**URL:** <https://forum.cmascenter.org/t/meganv3-1-processing-compilation/2442>\
**Category:** MEGAN\
**Created:** [June 21, 2021, 2:19pm UTC](https://forum.cmascenter.org/t/meganv3-1-processing-compilation/2442 "2021-06-21T14:19:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cicy996](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.cmascenter.org/cicy996/32/1261_2.png) [@cicy996](https://forum.cmascenter.org/u/cicy996)\
**Post date:** [June 21, 2021, 2:20pm UTC](https://forum.cmascenter.org/t/meganv3-1-processing-compilation/2442/1 "2021-06-21T14:20:00Z")

</div>

Dear all,

I am trying to compile the **MEGANv3.1 preprocessor** (Fortran program).  
Here is the Makefile I modified.

```auto
.SUFFIXES: .o .f90
F90 = gfortran
NETCDF_DIR = /disk/r071/cliucv/smoke/subsys/netcdf
LIBS = -L$(NETCDF_DIR)/lib -lnetcdf
INCLUDE_MODULES = -I$(NETCDF_DIR)/include
FFLAGS = -O3 -Bstatic

```

Then when I type _make_, here is the error.

```auto
gfortran -o prepmegan4cmaq_lai.x -O3 -Bstatic misc_definitions_module.o constants_module.o bio_types.o area_mapper.o prepmegan4cmaq_lai.o -L/disk/r071/cliucv/smoke/subsys/netcdf/lib -lnetcdf
area_mapper.o: In function `__area_mapper_MOD_area_interp2':
area_mapper.f90:(.text+0x3652): undefined reference to `nf_inq_varid_'
area_mapper.f90:(.text+0x3716): undefined reference to `nf_get_var_real_'
area_mapper.o: In function `__area_mapper_MOD_discrete_frac':
area_mapper.f90:(.text+0x747b): undefined reference to `nf_inq_varid_'
area_mapper.f90:(.text+0x7553): undefined reference to `nf_get_var_int_'
area_mapper.o: In function `__area_mapper_MOD_area_interp':
area_mapper.f90:(.text+0xb2d2): undefined reference to `nf_inq_varid_'
area_mapper.f90:(.text+0xb396): undefined reference to `nf_get_var_int_'
area_mapper.o: In function `__area_mapper_MOD_handle_ncerr.part.1.constprop.5':
area_mapper.f90:(.text.unlikely+0x42): undefined reference to `nf_strerror_'
prepmegan4cmaq_lai.o: In function `wrf_file.1887':
prepmegan4cmaq_lai.f90:(.text+0x112): undefined reference to `nf_open_'
prepmegan4cmaq_lai.f90:(.text+0x1af): undefined reference to `nf_inq_dimid_'
prepmegan4cmaq_lai.f90:(.text+0x22f): undefined reference to `nf_inq_dimlen_'
prepmegan4cmaq_lai.f90:(.text+0x2af): undefined reference to `nf_inq_dimid_'
prepmegan4cmaq_lai.f90:(.text+0x32f): undefined reference to `nf_inq_dimlen_'
prepmegan4cmaq_lai.f90:(.text+0x3b7): undefined reference to `nf_get_att_int_'
prepmegan4cmaq_lai.f90:(.text+0x4a2): undefined reference to `nf_get_att_real_'
prepmegan4cmaq_lai.f90:(.text+0x594): undefined reference to `nf_get_att_real_'
prepmegan4cmaq_lai.f90:(.text+0x688): undefined reference to `nf_get_att_real_'
prepmegan4cmaq_lai.f90:(.text+0x77a): undefined reference to `nf_get_att_real_'
prepmegan4cmaq_lai.f90:(.text+0x86c): undefined reference to `nf_get_att_real_'
prepmegan4cmaq_lai.o:prepmegan4cmaq_lai.f90:(.text+0x953): more undefined references to `nf_get_att_real_' follow
prepmegan4cmaq_lai.o: In function `wrf_file.1887':
prepmegan4cmaq_lai.f90:(.text+0xc74): undefined reference to `nf_close_'
prepmegan4cmaq_lai.o: In function `MAIN__':
prepmegan4cmaq_lai.f90:(.text+0x192d): undefined reference to `nf_open_'
prepmegan4cmaq_lai.f90:(.text+0x1a1f): undefined reference to `nf_inq_dimid_'
prepmegan4cmaq_lai.f90:(.text+0x1adc): undefined reference to `nf_inq_dimlen_'
prepmegan4cmaq_lai.f90:(.text+0x1b98): undefined reference to `nf_inq_dimid_'
prepmegan4cmaq_lai.f90:(.text+0x1c55): undefined reference to `nf_inq_dimlen_'
prepmegan4cmaq_lai.f90:(.text+0x1e3c): undefined reference to `nf_inq_varid_'
prepmegan4cmaq_lai.f90:(.text+0x1ef6): undefined reference to `nf_get_var_real_'
prepmegan4cmaq_lai.f90:(.text+0x2055): undefined reference to `nf_inq_varid_'
prepmegan4cmaq_lai.f90:(.text+0x210f): undefined reference to `nf_get_var_real_'
prepmegan4cmaq_lai.f90:(.text+0x31ab): undefined reference to `nf_close_'
prepmegan4cmaq_lai.f90:(.text+0x5c33): undefined reference to `nf_inq_varid_'
prepmegan4cmaq_lai.f90:(.text+0x5d7a): undefined reference to `nf_get_vara_real_'
prepmegan4cmaq_lai.o: In function `handle_ncerr.1880.part.0.constprop.1':
prepmegan4cmaq_lai.f90:(.text.unlikely+0x42): undefined reference to `nf_strerror_'
collect2: error: ld returned 1 exit status
make: *** [prepmegan4cmaq_lai.x] Error 1

```

Looking forward to your reply.

Chang

---

<div class="post-metadata">

**Author:** ![cjcoats](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@cjcoats](https://forum.cmascenter.org/u/cjcoats)\
**Post date:** [June 21, 2021, 2:48pm UTC](https://forum.cmascenter.org/t/meganv3-1-processing-compilation/2442/2 "2021-06-21T14:48:20Z")

</div>

See [https://cjcoats.github.io/ioapi/AVAIL.html#ncf4](https://cjcoats.github.io/ioapi/AVAIL.html#ncf4):  
For netCDF-4, you need to build both the netCDF-C _libnetcdf.a_ and the netCDF-Fortran _libnetcdff.a_ (and put both of them where the compiler can find them – _/disk/r071/cliucv/smoke/subsys/netcdf/lib_ in this case), and your compile/link command needs both of these, listing the Fortran-library first:

```auto
gfortran -o prepmegan4cmaq_lai.x -O3 -Bstatic misc_definitions_module.o constants_module.o bio_types.o area_mapper.o prepmegan4cmaq_lai.o -L/disk/r071/cliucv/smoke/subsys/netcdf/lib -lnetcdff.a -lnetcdf.a

```
