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

Re: 20031229: include issues for netCDF C++ build



>To: address@hidden
>From: "Matt Kennedy" <address@hidden>
>Subject: include issues
>Organization: NASA
>Keywords: 200312291514.hBTFEVp2015601 netCDF 3.5.1-beta13 C++ include

Hi Matt,

> When compiling src/cxx/example.cpp I get a number of undefined 
> references to netcdf calls.
> 
> I have used the following compiler options,
> g++ -I<PATH>netcdf-3.5.1-beta13/include -L<PATH>netcdf-3.5.1-beta13/lib 
> example.cpp -lnetcdf_c++
> 
> Here is a sample of the errors,
> 
> /disks/NASUSER/mkennedy/netcdf-3.5.1-beta13/lib/libnetcdf_c++.a(netcdf.o)(.text+0xf3):
>  
> In function `NcFile::num_dims() const':
> : undefined reference to `ncinquire'
> /disks/NASUSER/mkennedy/netcdf-3.5.1-beta13/lib/libnetcdf_c++.a(netcdf.o)(.text+0x133):
>  
> In function `NcFile::num_vars() const':
> : undefined reference to `ncinquire'
> /disks/NASUSER/mkennedy/netcdf-3.5.1-beta13/lib/libnetcdf_c++.a(netcdf.o)(.text+0x173):
>  
> In function `NcFile::num_atts() const':
> : undefined reference to `ncinquire'
> /disks/NASUSER/mkennedy/netcdf-3.5.1-beta13/lib/libnetcdf_c++.a(netcdf.o)(.text+0x193):
>  
> In function `NcFile::get_dim(char const*) const':
> : undefined reference to `ncdimid'
> 
> The beta c interface works fine with similar compilation flags (relative 
> to the c headers and libraries).  

You need to add "-lnetcdf" to the end of your g++ invocation.  If you
run "make test" in the src/cxx directory, you will see this is how
the test program is linked.  So use something like:

  g++ -o example -I<PATH>netcdf-3.5.1-beta13/include example.cpp 
-L<PATH>netcdf-3.5.1-beta13/lib -lnetcdf_c++ -lnetcdf

if you want to do the compile and link all in one step.

The default installation stores the C++ library in a different library
file than the C library, but I think you could use ld to combine them
into a single library for convenience.  There were portability
problems with trying to do this on all platforms, so the interfaces
are distributed to use separate libraries.

--Russ