1

first of all I've read this topic but I can't compile my code. Compiling Fortran netCDF programs on Ubuntu

I am on UBUNTU 14.04 and compiling a fortran program that uses NetCDF. I have compilation error like this:

terrain.f:(.text+0x17efd): undefined reference to 'ncopn_'
terrain.f:(.text+0x18111): undefined reference to 'ncopn_'
terrain.f:(.text+0x187cc): undefined reference to 'ncclos_'
terrain.f:(.text+0x187ea): undefined reference to 'ncclos_'

Definitely it says I have not netcdf fortran librarries. But I installed zlib, HDF5, netcdf C and netcdf Fortran according these web pages with disable shared and disable dap options.

http://www.unidata.ucar.edu/software/netcdf/docs/build_default.html http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-fortran-install.html

this is result of nc-config --libs command:

-L/usr/local/lib -L/usr/local -lnetcdf -lhdf5_hl -lhdf5 -ldl -lm -lz

this is result of nf-config --flibs command:

-L/usr/local/lib -lnetcdff -L/usr/local/lib -lnetcdf -lnetcdf -lhdf5_hl -lhdf5 -lz

i build my project with this command:

gfortran terrain.f -I/usr/local/include -L/usr/local/lib -lnetcdff -lnetcdf -lhdf5_hl -lhdf5 -lz -lm -ldl

what's wrong with this?

Edit: I use --disable-netcdf-4 option in configuring netcdf C and netcdf fortran and I can compile my code. So it's a problem with HDF5.

  • Can you show us your Fortran code? Or even better a minimal example? – Ian Ross Apr 23 '15 at 06:05
  • my code is so long. but I can run it on some other systems and it has proper includes in it. I'm running it in my system without installing hdf5 and with --disable-netcdf-4 option now. – Hadi bahmani jalali Apr 23 '15 at 06:21
  • 1
    possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Peter Petrik Apr 23 '15 at 07:18
  • One thing that surprises me is that the references are `ncopn_`, not `nf90_open__` or something like that. – chw21 Apr 23 '15 at 13:49
  • Those are old syntaxes and you can see them in unidata website. – Hadi bahmani jalali Apr 23 '15 at 16:24

1 Answers1

5

This isn't really an answer, but you need to produce more info. Write a bare-bones program, and show us the code. Then show us the command you use to try and compile.

Here are two examples:

Fortran 77:

$ cat test_nc.f

      PROGRAM TEST_NC
      IMPLICIT NONE
      include 'netcdf.inc'
      INTEGER ncid, nc_err

      nc_err = nf_open('test.nc', nf_nowrite, ncid)
      nc_err = nf_close(ncid)
      END PROGRAM TEST_NC

$ gfortran test_nc.f -o test_nc `nf-config --fflags --flibs`

Fortran 90:

$ cat test_nc.f90
program test_nc
    use netcdf
    implicit none
    integer :: ncid, nc_err

    nc_err = nf90_open('test.nc', nf90_nowrite, ncid)
    nc_err = nf90_close(ncid)
end program test_nc

$ gfortran test_nc.f90 -o test_nc `nf-config --fflags --flibs`

Both of these compile on my system without errors or even warnings.

chw21
  • 7,970
  • 1
  • 16
  • 31