mardi 29 janvier 2019

netCDF basic troubleshooting on C++11

So I'm trying to use netCDF along with C++. The installation is correct (I know since I'm running on a cluster and I know it works for other people there). Yet not even the example codes from the netCDF webpage are working...

I am using g++ -std=c++11 to compile. Whenever I try to compile one of the several example codes I have for using netCDF I get a bunch of errors, and I have no idea what's going on...

#include <vector>
#include <netcdf>
using namespace netCDF;
int main() {
  int nx = 6, ny = 12;
  int dataOut[nx][ny];
  for(int i = 0; i < nx; i++)
    for(int j = 0; j < ny; j++)
    dataOut[i][j] = i * ny + j;
  // Create the netCDF file.
  NcFile dataFile("1st.netCDF.nc",NcFile::replace);
  // Create the two dimensions.
  NcDim xDim = dataFile.addDim("x",nx);
  NcDim yDim = dataFile.addDim("y",ny);
  std::vector<NcDim> dims(2);
  dims[0] = xDim;
  dims[1] = yDim;
  // Create the data variable.
  NcVar data =  dataFile.addVar("data", ncInt, dims);
  // Put the data in the file.
  data.putVar(&dataOut);
  // Add an attribute.
  dataFile.putAtt("Creation date:",
  "12 Dec 2014");
  return 0;
}

The expected result is a correct compilation of the code, and once it's run to get a .nc file with the dataOut recorded into it. This is my actual output when I try to compile:

/tmp/ccyuchst.o: In function main': rarray_2_netcdf.cc:(.text+0x1c6): undefined reference tonetCDF::NcFile::NcFile(std::__cxx11::basic_string, std::allocator > const&, netCDF::NcFile::FileMode)' rarray_2_netcdf.cc:(.text+0x234): undefined reference to netCDF::NcGroup::addDim(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long) const' rarray_2_netcdf.cc:(.text+0x2a2): undefined reference tonetCDF::NcGroup::addDim(std::__cxx11::basic_string, std::allocator > const&, unsigned long) const' rarray_2_netcdf.cc:(.text+0x322): undefined reference to netCDF::NcDim::operator=(netCDF::NcDim const&)' rarray_2_netcdf.cc:(.text+0x34b): undefined reference tonetCDF::NcDim::operator=(netCDF::NcDim const&)' rarray_2_netcdf.cc:(.text+0x399): undefined reference to netCDF::ncInt' rarray_2_netcdf.cc:(.text+0x3a1): undefined reference tonetCDF::NcGroup::addVar(std::__cxx11::basic_string, std::allocator > const&, netCDF::NcType const&, std::vector > const&) const' rarray_2_netcdf.cc:(.text+0x3d5): undefined reference to netCDF::NcVar::putVar(void const*) const' rarray_2_netcdf.cc:(.text+0x441): undefined reference tonetCDF::NcGroup::putAtt(std::__cxx11::basic_string, std::allocator > const&, std::__cxx11::basic_string, std::allocator > const&) const' rarray_2_netcdf.cc:(.text+0x4d6): undefined reference to netCDF::NcFile::~NcFile()' rarray_2_netcdf.cc:(.text+0x63e): undefined reference tonetCDF::NcFile::~NcFile()' /tmp/ccyuchst.o: In function void std::_Construct<netCDF::NcDim>(netCDF::NcDim*)': rarray_2_netcdf.cc:(.text._ZSt10_ConstructIN6netCDF5NcDimEJEEvPT_DpOT0_[_ZSt10_ConstructIN6netCDF5NcDimEJEEvPT_DpOT0_]+0x2e): undefined reference tonetCDF::NcDim::NcDim()' /tmp/ccyuchst.o: In function netCDF::NcGroupAtt::~NcGroupAtt()': rarray_2_netcdf.cc:(.text._ZN6netCDF10NcGroupAttD2Ev[_ZN6netCDF10NcGroupAttD5Ev]+0x20): undefined reference tonetCDF::NcAtt::~NcAtt()' collect2: error: ld returned 1 exit status

Aucun commentaire:

Enregistrer un commentaire