Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29253 Discussions

NETCDF build and problems with linking in ifort

larangunn
Beginner
2,174 Views
I am very much a beginner at this kind of thing so if anyone could help me out that would be great.

I have been trying to build the netcdf libraries on my Mac OS 10.6.7 system for a while now. I am using the intel C++ (version 12.0.3) and ifort (version 11.1) compilers. Everything seem to be fine and following all the online notes I have a lib directory with a number of library files. However, when it comes to running my fortran code I get this error

Undefined symbols:
"_netcdf_mp_nf90_open_", referenced from:
_MAIN__ in run_rttov.o
ld: symbol(s) not found

It is a very simple code I am running, I am just testing the setup by having the program open a netcdf file.

I run it will the following command

ifort -c -I/usr/local/include -L/usr/local/lib -lnetcdf -lcurl simple.F90

This work but then when I take the next step

ifort -I/usr/local/include -L/usr/local/lib -lnetcdf -lcurl simple.o

If anyone has an idea of where I am going wrong I would really appreciate the help

Thanks


0 Kudos
5 Replies
Ron_Green
Moderator
2,174 Views
We can decipher that missing symbol to help us;

_netcdf_mp_nf90_open_

"mp" tells us this is a Module Procedure. 'netcdf' is the module, and the procedure is 'nf90_open' that is missing.

Do you have a USE netcdf in the code calling netcdf? And in the netcdf sources, is procedure nf90_open defined?

if you

nm libnetcdf.a | grep -i nf90_open

do the symbol appear and does it have the Target attibute "T" and not the undefined reference "U"?

ron
0 Kudos
larangunn
Beginner
2,174 Views
Hi

I do have the use netcdf in my program yes

If I do nm libnetcdf.a | grep -i nf90_open

I see nothing but if I do that on

nm libnetcdff.a | grep -i nf90_open

I get

000000000000148a T _netcdf_mp_nf90_open_
0000000000003f9e T _netcdf_mp_nf90_open_mp_

Does that mean I'm looking in the wrong place?

Thanks
Lara
0 Kudos
larangunn
Beginner
2,174 Views
Hi

Thanks for your help I just fixed it I think.

I just need to call it like this

ifort -I/... -L/... -lnetcdf -lnetcdff -lcurl simple.F90

That seems to have worked.

Thanks
Lara
0 Kudos
Ron_Green
Moderator
2,174 Views
cool, no, it means you need to link in this Fortran interface to netcdf with the other libraries, -lnetcdff

OPPS you beat me to the solution. :)

ron
0 Kudos
TimP
Honored Contributor III
2,174 Views
I think the recommended order is -lnetcdff -lnetcdf
We all seem to be hitting the same question; current netcdf has this separate Fortran library, which isn't mentioned in the build instructions of individual applications.
0 Kudos
Reply