我正在尝试在我的C ++代码中设置netCDF,以将数据转换为多种数据类型以便于转换。我有一个c库的预构建版本,并且已经从gitHub下载了cxx4版本。但是,每当我尝试调用这些函数时,都会收到外部引用错误,这表明未包含必需的库。
我遵循了从多个不同答案中回答相似问题的步骤,但是没有一个对我有用。
我已将所有库,bin和include文件夹包括在必要的目录中,并将它们放在项目的属性中。我还将所有.lib文件包括在其他依赖项中,包括netcdf.lib。
当我查看项目的外部依赖项时,我可以在那里找到所有文件,但是程序似乎在以某种方式访问它们时遇到了问题。不知道是什么问题。
#pragma once
#include <stdlib.h>
#include <stdio.h>
/* This is part of the netCDF package.
Copyright 2006 University Corporation for Atmospheric Research/Unidata.
See COPYRIGHT file for conditions of use.
This is a very simple example which writes a 2D array of
sample data. To handle this in netCDF we create two shared
dimensions, "x" and "y", and a netCDF variable, called "data".
This example is part of the netCDF tutorial:
http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-tutorial
Full documentation of the netCDF C++ API can be found at:
http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-cxx
$Id: simple_xy_wr.cpp,v 1.5 2010/02/11 22:36:43 russ Exp $
*/
#include <iostream>
#include <netcdf>
#include <vector>
using namespace std;
using namespace netCDF;
//using namespace netCDF::exceptions;
// We are writing 2D data, a 6 x 12 grid.
static const int NX = 6;
static const int NY = 12;
// Return this in event of a problem.
static const int NC_ERR = 2;
class netCDFTest
{
public:
netCDFTest() {
}
~netCDFTest()
{
}
void TestNetCDF()
{
// This is the data array we will write. It will just be filled
// with a progression of numbers for this example.
int dataOut[NX][NY];
// Create some pretend data. If this wasn't an example program, we
// would have some real data to write, for example, model output.
for (int i = 0; i < NX; i++)
for (int j = 0; j < NY; j++)
dataOut[i][j] = i * NY + j;
// The default behavior of the C++ API is to throw an exception i
// an error occurs. A try catch block is necessary.
try
{
// Create the file. The Replace parameter tells netCDF to overwrite
// this file, if it already exists.
NcFile dataFile("simple_xy.nc", NcFile::replace);
// Create netCDF dimensions
NcDim xDim = dataFile.addDim("x", NX);
NcDim yDim = dataFile.addDim("y", NY);
// Define the variable. The type of the variable in this case is
// ncInt (32-bit integer).
vector<NcDim> dims;
dims.push_back(xDim);
dims.push_back(yDim);
NcVar data = dataFile.addVar("data", ncInt, dims);
// Write the data to the file. Although netCDF supports
// reading and writing subsets of data, in this case we write all
// the data in one operation.
data.putVar(dataOut);
// The file will be automatically close when the NcFile object goes
// out of scope. This frees up any internal netCDF resources
// associated with the file, and flushes any buffers.
cout << "*** SUCCESS writing example file simple_xy.nc!" << endl;
}
catch (string err)
{
cout << "The error is: " << err;
}
}
};
我试图复制它们只是一个简单的示例,希望它可以将数据输出到文件中,但是,它仅返回未解决的外部符号错误,如下所示。
unresolved external symbol "public: void __thiscall netCDF::NcVar::putVar(void const *)const " (?putVar@NcVar@netCDF@@QBEXPBX@Z) referenced in function "public: void __thiscall netCDFTest::TestNetCDF(void)" (?TestNetCDF@netCDFTest@@QAEXXZ)
我知道这是一个图书馆问题,但对于如何解决它一无所知。
任何帮助将不胜感激。