[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netCDF #ZDR-128646]: Ncfile for cpp



> Russ,
> I finally switch to fortran instead of using c++ to read netcdf file. It
> works fine. For the last question, would you please tell me the environment
> variables for NETCDF?

The netCDF library is intended to be portable to non-Unix systems, and thus 
makes no use of environment variables.  And for the purpose you have in mind,
g77 would have to understand the environment variables to know where to link
from.

> When I compile g77, I type 'g77 -o test -L/lib test1.f', it has no problem.
> However, when I type 'g77 -o test test1.f', undefined references appear.
> This means that the netcdf library isn't linked properly, right?

No, it just means you didn't tell g77 where the netCDF library is installed.
If you install it in /usr/lib (and the include files in /usr/include), then
you don't have to tell g77 where to find the library, but otherwise, you do.

The netCDF utility "nc-config" can be of some help here, becasue it's built to 
know where things are installed.  So if you invoke "nc-config --flibs", for 
example, it tells you what options are needed to find the Fortran library.

You can even use this on the g77 command line, for example:

  g77 `nc-config --fflags` -o test test1.f `nc-config --flibs`

so you don't have to know where things are installed.

> Therefore, I would like to set the netcdf environment variables in my
> .bashrc file. I've tried 'NETCDF=/usr/local/netcdf',where is the location of
> my netcdf, but it seems useless.

--Russ

> --------------------------------------------------
> From: "Unidata netCDF Support" <address@hidden>
> Sent: Friday, September 03, 2010 2:52 AM
> To: <address@hidden>
> Cc: <address@hidden>
> Subject: [netCDF #ZDR-128646]: Ncfile for cpp
> 
> > Camilla
> >
> >> Really thank you for your help. However, there are some more undefined
> >> references displayed. Are there anything missing? Also, as for the links
> >> for
> >> the library and include files, can I set them as system environment
> >> variables in my .bashrc file?
> >
> > The errors you are getting, such as
> >
> >> /lib/libnetcdf_c++.a(netcdf.o): In function
> >> `_ZNK16NcTypedComponent9get_spaceEl':
> >> /home/koshiro/netcdf-3.6.2/cxx/netcdf.cpp:563: undefined reference to
> >> `___gxx_personality_sj0'
> >> /home/koshiro/netcdf-3.6.2/cxx/netcdf.cpp:563: undefined reference to
> >> `__Unwind_SjLj_Register'
> >> /home/koshiro/netcdf-3.6.2/cxx/netcdf.cpp:586: undefined reference to
> >> `__Unwind_SjLj_Unregister'
> >
> > are not related to netCDF, but to something wrong with the way you are
> > trying to compile and link your program.  You can google the phrase
> >
> >  undefined reference to ___gxx_personality_sj0
> >
> > to see what I mean about not being related to netCDF.  You would get
> > similar errors if you used gcc instead of g++, or if you used a
> > different C++ compiler than what you used to build the library in
> > cygwin.  You might also get these errors if you didn't install
> > everything needed for g++ development in your cygwin environment.
> >
> > If you have built the 4.1.1 version of the library, you might see how
> > the C++ examples are compiled and linked, and follow that pattern.
> > Unfortunately the examples are compiled and linked before the
> > libraries are installed, so the compiling and linking flags use
> > a complicated utility named "libtool" and get the libraries from
> > directories where they were first built.
> >
> > Another thing you could try is the 4.1.1 version of the "nc-config"
> > utility, to show how the library flags need to appear on the link
> > line.  For example, if your netCDF utilities are installed in
> > /usr/local/lib/bin, you could run
> >
> >  /usr/local/lib/bin/nc-config --libs
> >
> > and it would show the options for specifying library directories and
> > libraries in the right order.
> >
> > However, there might still be extra C++ runtime libraries that you
> > would need to specify to your C++ compiler, if it wasn't installed to
> > know where those are, such as "-lg++".  And you must be using the same
> > g++ compiler you used to create the libnetcdf_c++ library, to get the
> > "name mangling" right.
> >
> > I don't know much more about the C++ netCDF library, so I hope this
> > helps.
> >
> > --Russ
> >
> > Russ Rew                                         UCAR Unidata Program
> > address@hidden                      http://www.unidata.ucar.edu
> >
> >
> >
> > Ticket Details
> > ===================
> > Ticket ID: ZDR-128646
> > Department: Support netCDF
> > Priority: Normal
> > Status: Closed
> >
> >
> 
> 

Russ Rew                                         UCAR Unidata Program
address@hidden                      http://www.unidata.ucar.edu



Ticket Details
===================
Ticket ID: ZDR-128646
Department: Support netCDF
Priority: Normal
Status: Closed