[SOLVED] netcdf configure using gfortran

Discussion on computers, ROMS installation and compiling

Moderators: arango, robertson

Post Reply
Message
Author
sbergman
Posts: 5
Joined: Mon May 10, 2010 2:08 pm
Location: Dept of Environmental Affairs - SA Governemt (& Oceanography SA)

[SOLVED] netcdf configure using gfortran

#1 Unread post by sbergman »

Hi,

I'm currently having trouble getting the upwelling test case to compile. I've successfully compiled and ran this case on another PC, so I'm confident that the error isnt related to the build.bash file.

I've read somewhere that it may be related to when I ran ./configure after installing latest version of netcdf.

I used
./configure --prefix=/home/username/local

but understand I may have needed to pass some more arguments to get it to configure with the gfortran compiler I use for ROMS.

Can someone here perhaps help me out with the correct ./configure command so I can reinstall netcdf ?

Thanks
Last edited by sbergman on Thu Jul 28, 2011 12:27 pm, edited 1 time in total.

User avatar
kate
Posts: 4088
Joined: Wed Jul 02, 2003 5:29 pm
Location: CFOS/UAF, USA

Re: netcdf configure using gfortran

#2 Unread post by kate »

As ever, it depends. Here's what I used last (on Linux):

Code: Select all

configure FC=gfortran F77=gfortran F90=gfortran CXX=g++ --prefix=/u1/uaf/kate --enable-netcdf4 --enable-shared --with-hdf5=/u1/uaf/kate

User avatar
m.hadfield
Posts: 521
Joined: Tue Jul 01, 2003 4:12 am
Location: NIWA

Re: netcdf configure using gfortran

#3 Unread post by m.hadfield »

kate wrote:As ever, it depends. Here's what I used last (on Linux):

Code: Select all

configure FC=gfortran F77=gfortran F90=gfortran CXX=g++ --prefix=/u1/uaf/kate --enable-netcdf4 --enable-shared --with-hdf5=/u1/uaf/kate
With the latest release of netCDF-4 (4.1.3) you don't use "--with-hdf5" to specify the location of the HDF5 libraries, you use CPPFLAGS and LDFLAGS. Also, I don't think F77 and F90 are required (or possibly even allowed) with this version. The above command would become

Code: Select all

configure FC=gfortran CXX=g++ CPPFLAGS=-I/u1/uaf/kate/include LDFLAGS=-L/u1/uaf/kate/lib --prefix=/u1/uaf/kate --enable-netcdf4 --enable-shared
Or maybe "LDFLAGS=-L/u1/uaf/kate/lib64" if that's where the HDF5 libraries are installed.

To the original poster, I suggest you do use 4.1.3, as the netCDF developers have put a lot of work into cleaning up the build process and the operation of the nc-config script.

User avatar
kate
Posts: 4088
Joined: Wed Jul 02, 2003 5:29 pm
Location: CFOS/UAF, USA

Re: netcdf configure using gfortran

#4 Unread post by kate »

Thanks, Mark, my last build was way back at 4.1.1.

User avatar
m.hadfield
Posts: 521
Joined: Tue Jul 01, 2003 4:12 am
Location: NIWA

Re: netcdf configure using gfortran

#5 Unread post by m.hadfield »

kate wrote:Thanks, Mark, my last build was way back at 4.1.1.
Ancient history. :wink:

sbergman
Posts: 5
Joined: Mon May 10, 2010 2:08 pm
Location: Dept of Environmental Affairs - SA Governemt (& Oceanography SA)

Re: netcdf configure using gfortran

#6 Unread post by sbergman »

Hi again, thanks to both of you I've got netcdf-4.1.3 installed.

For the record, I did a

Code: Select all

make clean
and then a

Code: Select all

./configure FC=gfortran CXX=g++ CPPFLAGS=-I/home/sbergman/local/include LDFLAGS=-L/home/sbergman/local/lib --prefix=/home/sbergman/local --disable-netcdf-4 --enable-shared
and then a

Code: Select all

make check install
Note the:

Code: Select all

--disable-netcdf-4
something went wrong if I enabled this. I didnt figure out why but it seems to work if I disable this option.

However when I compile the upwelling example, I still get underfined reference errors to files / routines with the double-underscore. The end of the error messages look like this

Code: Select all

mod_netcdf.f90:(.text+0x11474): undefined reference to `__netcdf_MOD_nf90_get_var_1d_eightbytereal'
mod_netcdf.f90:(.text+0x11925): undefined reference to `__netcdf_MOD_nf90_get_var_1d_eightbytereal'
/home/sbergman/MyROMSProjects/Upwelling/Build/libMODS.a(mod_netcdf.o): In function `T.2871':
mod_netcdf.f90:(.text+0x11a42): undefined reference to `__netcdf_MOD_nf90_inq_varid'
mod_netcdf.f90:(.text+0x11a8a): undefined reference to `__netcdf_MOD_nf90_get_var_eightbytereal'
/home/sbergman/MyROMSProjects/Upwelling/Build/libMODS.a(mod_netcdf.o): In function `__mod_netcdf_MOD_netcdf_check_dim':
mod_netcdf.f90:(.text+0x138b6): undefined reference to `__netcdf_MOD_nf90_inquire'
mod_netcdf.f90:(.text+0x1396a): undefined reference to `__netcdf_MOD_nf90_inquire_dimension'
collect2: ld returned 1 exit status
make: *** [/home/sbergman/MyROMSProjects/Upwelling/oceanS] Error 1
If you have any further suggestions, please let me know.
Regards,
- S

User avatar
kate
Posts: 4088
Joined: Wed Jul 02, 2003 5:29 pm
Location: CFOS/UAF, USA

Re: netcdf configure using gfortran

#7 Unread post by kate »

See if this is helpful. It could be a "-fno-second-underscore" kind of answer or the -lnetcdff issue.

User avatar
m.hadfield
Posts: 521
Joined: Tue Jul 01, 2003 4:12 am
Location: NIWA

Re: netcdf configure using gfortran

#8 Unread post by m.hadfield »

Hi sbergman

Have a look at the command that triggered those errors in building ROMS--post it here if you want. Does the linker command line have the options you expect? I would expect it to end with "-lnetcdff -lnetcdf". does it?

I don't think you need to worry about "-fno-second-underscore" or any of the other GCC options relating to code-generation conventions. (I think the two leading underscores in the undefined references are just part of the name-mangling for subroutines in the Fortran 90 interface and not related to the old G77-style name mangling, which added trailing underscores--either 1 or 2 depending on the day of the week or something. All ancient history now, I hope.)

The fact that you had to disable netcdf-4 in building netCDF shouldn't be a problem for now. It just means you have a netCDF-4 library that supports only the netCDF-3 interface. ROMS should be satisfied with that, until you try to use netCDF-4 output features. However it does suggest there was something wrong with these arguments in the configure command:

Code: Select all

CPPFLAGS=-I/home/sbergman/local/include LDFLAGS=-L/home/sbergman/local/lib
They are supposed to indicate where HDF5 is installed and the fact you couldn't build with --enable-netcdf-4 suggests this wasn't successful. Or some other problem.

PS: You did activate USE_NETCDF4 when building ROMS, didn't you?

sbergman
Posts: 5
Joined: Mon May 10, 2010 2:08 pm
Location: Dept of Environmental Affairs - SA Governemt (& Oceanography SA)

Re: netcdf configure using gfortran

#9 Unread post by sbergman »

Hi again. Thanks for the help so far.

I've got

Code: Select all

#export USE_NETCDF4=on            # compile with NetCDF-4 library
in my build.bash file. Am I correct in saying that its commented out cos I configured netcdf with the --disable-netcdf4 option? (and it's like that on the working pc...)

I tried doing a ./build.bash >> compilelog.txt and searched through that txt file for any clues.
The last line (where I assume) things went awry looks like this:

Code: Select all

/usr/bin/gfortran -frepack-arrays -O3 -ffast-math  /home/sbergman/MyROMSProjects/Upwelling/Build/esmf_roms.o /home/sbergman/MyROMSProjects/Upwelling/Build/master.o /home/sbergman/MyROMSProjects/Upwelling/Build/ocean_control.o /home/sbergman/MyROMSProjects/Upwelling/Build/ocean_coupler.o /home/sbergman/MyROMSProjects/Upwelling/Build/propagator.o /home/sbergman/MyROMSProjects/Upwelling/Build/roms_export.o /home/sbergman/MyROMSProjects/Upwelling/Build/roms_import.o -o /home/sbergman/MyROMSProjects/Upwelling/oceanS /home/sbergman/MyROMSProjects/Upwelling/Build/libUTIL.a /home/sbergman/MyROMSProjects/Upwelling/Build/libNLM.a /home/sbergman/MyROMSProjects/Upwelling/Build/libNLM_bio.a /home/sbergman/MyROMSProjects/Upwelling/Build/libNLM_sed.a /home/sbergman/MyROMSProjects/Upwelling/Build/libANA.a /home/sbergman/MyROMSProjects/Upwelling/Build/libUTIL.a /home/sbergman/MyROMSProjects/Upwelling/Build/libMODS.a -L/home/sbergman/local/lib -lnetcdf
It looks like it was missing the -lnetcdff
I followed through kate's links, through the FAQ and ended up editing the file ~/ROMS/src/Compilers/Linux-gfortran.mk (on line 51 in my case) to

Code: Select all

LIBS := -L$(NETCDF_LIBDIR) -lnetcdff -lnetcdf
while there I also noticed that it was pointing to

Code: Select all

    NETCDF_INCDIR ?= /usr/local/include
    NETCDF_LIBDIR ?= /usr/local/lib
and I changed this to where my lib and include should be (according to my netcdf configure command).

Good news is that it compiled, but bad news is that I now get a runtime error which says:

Code: Select all

./oceanS: error while loading shared libraries: libnetcdff.so.5: cannot open shared object file: No such file or directory
I've tried reinstalling netcdf and putting everything in /usr/local/.... so I undid those extra changes to Linux-gfortran.mk but the problem still arises.

I looked for the libnetcdff.so.5 in the /usr/local/lib folder and found that it links to a libnetcdff.so.5.1.0 in the same folder - both are definitely there.

Any further suggestions?

- S

User avatar
kate
Posts: 4088
Joined: Wed Jul 02, 2003 5:29 pm
Location: CFOS/UAF, USA

Re: netcdf configure using gfortran

#10 Unread post by kate »

sbergman wrote:I've got

Code: Select all

#export USE_NETCDF4=on            # compile with NetCDF-4 library
in my build.bash file. Am I correct in saying that its commented out cos I configured netcdf with the --disable-netcdf4 option? (and it's like that on the working pc...)
No, you want to have USE_NETCDF4 on so that you pick up the nc-config during the build - it knows to include -lnetcdff for you.
Good news is that it compiled, but bad news is that I now get a runtime error which says:

Code: Select all

./oceanS: error while loading shared libraries: libnetcdff.so.5: cannot open shared object file: No such file or directory
Any further suggestions?
What is in your LD_LIBRARY_PATH environment variable? Are you running on the command line or from a batch script? Does the batch script have the right environment to find /usr/local?

sbergman
Posts: 5
Joined: Mon May 10, 2010 2:08 pm
Location: Dept of Environmental Affairs - SA Governemt (& Oceanography SA)

Re: netcdf configure using gfortran

#11 Unread post by sbergman »

Hi,

I think you guys have solved the problem:

There was no reference to LD_LIBRARY_PATH in my ~/.bashrc so I added the following:

Code: Select all

LD_LIBRARY_PATH=/home/sbergman/local/lib
export LD_LIBRARY_PATH
and things fell into place. So the upwelling example is running at the moment.

Mind you, since yesterday I've also installed zlib, hdf and rebuilt netcdf to include those options, thinking that my initial problem was caused, for some reason, by NOT enabling netcdf4. Followed that entire process through and then found out about editing the .bashrc file. At least the spin-off advantage is that I've got netcdf-4 working now.

A side-issue is that I had a confusing problem after installing zlib - I got a segmentation fault on synaptic and after rebooting the pc, no login prompt would appear though the xserver would start. Turns out that zlib conflicts with gdm. I uninstalled zlib and reinstalled it somewhere under my /home directory (ie: ./configure --prefix=/home/sbergman/local/) hoping that it'd avoid the conflict... I guess it did.

Thanks for the assistance!
- S

User avatar
m.hadfield
Posts: 521
Joined: Tue Jul 01, 2003 4:12 am
Location: NIWA

Re: [SOLVED] netcdf configure using gfortran

#12 Unread post by m.hadfield »

That zlib issue is an odd one! I guess it shows that life isn't meant to be easy. I'm glad you got it sorted out. :D

Post Reply