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

[netCDF #UHO-898473]: question: linking with netCDF C++ 4.1.3.



Hi Bill,

> //I'm having trouble linking my C++ test program with the //netCDF C++
> version 4.1.3 library.  I do not have the option of using version 4.2.
> The program compiles cleanly.  Here's the source:/
> 
> #include <iostream>
> #include <string>
> 
> #include "/mgt/dev/apps/common/netcdf4/include/netcdfcpp.h"
> 
> int main ( int argc , const char ** argv )
> 
> {
> 
> std::cout << "\nPlease enter the name of the netCDF file "
> << "that you want me to *try* to read."
> << std::endl;
> std::cout << ':';
> 
> std::string filename;
> std::cin >> filename;
> 
> std::cout << "\nThe filename you entered is:\n\""
> << filename
> << "\".\n"
> << std::endl;
> 
> NcFile testfile ( filename.c_str () );
> 
> if  (testfile.is_valid () == 0)
> {
> std::cout << "Version 4.1.3 of the netCDF C++ library "
> << "cannot handle this file.\n"
> << std::endl;
> return 0;
> }
> 
> return 0;
> 
> }
> 
> /Here's what I get when I t//ry to build:/
> 
> address@hidden netcdf413]$ g++ -o main main.C
> -L/mgt/dev/apps/common/netcdf4/lib/ -lnetcdf_c++4

The problem is using the wrong library.  Your program calls the 
netCDF C++ "legacy" library API, but you are trying to link with 
a non-compatible newer version of the netCDF-4 C++ library.  If
you built successfully from netcdf-4.1.3, you should have
installed libnetcdf_c++ files in the lib/ directory your linking
with, in which case you can just use "-lnetcdf_c++" instead of
"-lnetcdf_c++4" for linking your program.

In case you want to use it, the newer netcdf-4 C++ library is
available and explained in the Readme documentation appearing
at the bottom of this web page:

  https://github.com/Unidata/netcdf-cxx4

but it's not upward compatible with the legacy API.

--Russ

> /tmp/ccwzCfrW.o: In function `main':
> main.C:(.text+0x127): undefined reference to `NcFile::NcFile(char
> const*, NcFile::FileMode, unsigned long*, unsigned long,
> NcFile::FileFormat)'
> main.C:(.text+0x130): undefined reference to `NcFile::is_valid() const'
> main.C:(.text+0x185): undefined reference to `NcFile::~NcFile()'
> main.C:(.text+0x194): undefined reference to `NcFile::~NcFile()'
> collect2: ld returned 1 exit status
> address@hidden netcdf413]$
> 
> /What am I doing wrong?  ....or what am I not doing that I should be
> doing?  I and two co-workers are s//tumped.//
> //
> //Thank-you in advance for your help.//
> //Bill./
> 
> --
> William (Bill) Mattison
> NCWCP, cubicle 3693.
> 301-683-3272.
> 
> 
> 
Russ Rew                                         UCAR Unidata Program
address@hidden                      http://www.unidata.ucar.edu



Ticket Details
===================
Ticket ID: UHO-898473
Department: Support netCDF
Priority: Normal
Status: Closed


NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.