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

Re: 20030123: netCDF and C++



>To: address@hidden
>From: Martin Kolleck <address@hidden>
>Subject: netCDF and C++
>Organization: Deutsches Zentrum fuer Luft- und Raumfahrt
>Keywords: 200301230730.h0N7Uex14794 netCDF C++

Hi Martin,

> I am a developer for the DNW (German-Dutch Wind Tunnels). I am to write 
> an application which transforms our native data format into netCDF using 
> C++. Unfortunately, the libraries for C++ do not seem to work properly, 
> although they are found by the linker. Writing in C just works fine and 
> the compiling the C++ sources also works. I am getting the following 
> error message:
> 
> Undefined symnbol first referenced in file:
> NcFile::NcFile(char const *, NcFile::FileMode, unsigned int *, unsigned 
> int)Wdf.o
> 
> Do I have to set some special linker options or define some special 
> variable in my C++ sources. The only documentation about the C++ 
> Interface  I found so far is at
> 
> http://www.unidata.ucar.edu/packages/netcdf/cxxdoc_toc.html
> 
> I would appreciate any help you can offer. (Sample sources for C++ etc.)

First, make sure you are linking to the C++ library as well as the C
library, since they are distinct.  For example, after installing the
netCDF libraries in /usr/local/lib/ here is how you would link a C++
program, using the g++ compiler on a Unix system, for example:

 g++ -o nctst nctst.o -L/usr/local/lib -lnetcdf_c++ -lnetcdf

and similarly for any other C++ compiler.  I think you have to use the
same C++ compiler the C++ library was compiled with.  If this doesn't
work, you should check that the C++ library was actually built and
installed, since it is possible to specify that no C++ library is to
be built on installation.  You can check this by listing the library
files in the installation directory.  For example, here we have:

  $ ls -l /usr/local/lib/*netcdf*
  -rw-r--r--   1 russ     ustaff    858696 Oct  8 10:49 libnetcdf.a
  -rw-r--r--   1 russ     ustaff    142400 Oct  8 10:49 libnetcdf_c++.a

If you still can't link with the library, or it was built without the
C++ option, you might want to try building the netCDF libraries again
from the latest beta-test release, which has some changes to the C++
interface to conform to the latest C++ standards enforced by recent
C++ compilers such as the 3.x versions of g++.  It is available from

  ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-beta.tar.Z

and has been tested on several platforms and C++ compilers.  After you
build it, running "make test" will build and test a C++ program and
you can mimic the way that program is linked by looking at the output
from "make test".

--Russ

_____________________________________________________________________

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