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

[netCDF #DNS-970730]: Error with netcdf



Hello Nishant,

Thanks for providing the additional information.  

A couple of notes; you don't mention which version of gcc/g++ you're using, or 
which flavor of Ubuntu.   However, I can try to hazard a couple of guesses.  
The errors you are getting suggest that g++ is unable to find a library 
containing those symbols it refers to as 'undefined references'.  Are you 
certain '-lnetcdf_c++4' is correct for your system? If so, it is a non-standard 
name; the default argument would be '-lnetcdf_cxx4'.  The errors are also 
'linker' errors, which I'm surprised to see; the '-c' flag you are passing to 
g++ tell the compiler to only run preprocess, compile and assemble steps.  On 
my system, at least, using g++ with the '-c' argument results in warnings that 
the linker options are all unnecessary, and it successfully compiles to a `.o` 
object, pending linking.

Please confirm that the library file name is correct, and perhaps confirm that 
you are passing the '-c' argument to g++.  If you are, what happens when you 
exclude it?

Thanks, I'm sure we'll be able to figure this out,

-Ward

> Full Name: Nishant Sharma
> Email Address: address@hidden
> Organization: San Jose State University
> Package Version:
> Operating System: Ubuntu
> Hardware:
> Description of problem: Hi,
> I'm getting following error. Please let me know if you need any other details.
> 
> Code
> 
> #include <iostream>
> #include <iomanip>
> #include <netcdf>
> 
> using namespace std;
> using namespace netCDF;
> using namespace netCDF::exceptions;
> 
> 
> int main()
> {
> 
> NcFile
> dataFile("/home/nishant/Documents/SJSU/CMPE275/Project/test/20140101_0000.gz",NcFile::read);
> cout<<"there are "<<dataFile.getVarCount()<<" variables"<<endl;
> 
> 
> }
> 
> 
> 
> readfile.o: In function `main':
> readfile.cpp:(.text+0x5a): undefined reference to
> `netCDF::NcFile::NcFile(std::string const&, netCDF::NcFile::FileMode)'
> readfile.cpp:(.text+0x83): undefined reference to
> `netCDF::NcGroup::getVarCount(netCDF::NcGroup::Location) const'
> readfile.cpp:(.text+0xc4): undefined reference to `netCDF::NcFile::~NcFile()'
> readfile.cpp:(.text+0xeb): undefined reference to `netCDF::NcFile::~NcFile()'
> readfile.cpp:(.text+0x116): undefined reference to `netCDF::NcFile::~NcFile()'
> collect2: error: ld returned 1 exit status
> 
> I m using
> C version :netcdf-4.3.3
> C++ API :netcdf-cxx4-4.2.1
> Command I m using
> 
> g++ -c -I/usr/local/include -L/usr/local/lib  -lnetcdf_c++4 -lnetcdf -lm  
> "readfile.cpp"
> 
> 
> 
> 
> 
> 

Ticket Details
===================
Ticket ID: DNS-970730
Department: Support netCDF
Priority: Normal
Status: Closed