0

I need to work with the NetCDF Format in C++ (I use Visual Studio as an IDE) and the C++ interface seems to be problematic, so I want to use the C Library as it is avaiable as a prebuilt library:

https://www.unidata.ucar.edu/software/netcdf/docs/winbin.html

I used the NetCDF-4 32-bit Version. Now I have my .nc files saved in some folder and want to open these with the method ncopen as below:

#include<netcdf.h>
#include<string>
#include<iostream>

using namespace std;
int main() {
    const char* pathPointer = "foo";
    int ncid;
    int status;
    status = nc_open(pathPointer, NC_NOWRITE, &ncid); 
    return 0;
}

But now, I get the following errors:

LNK2019 unresolved external symbol _nc_open referenced in function _main NetCDFtest C:\Users\Marcel\Documents\Visual Studio 2019\Projects\NetCDFtest\NetCDFtest\Quelle.obj 1

LNK1120 1 unresolved externals NetCDFtest C:\Users\Marcel\Documents\Visual Studio 2019\Projects\NetCDFtest\Debug\NetCDFtest.exe 1

I think that I linked everything properly, I tried it as in the answer of the following post:

Visual Studio - adding netCDF library

So, I do not know what the problem could be. As it is a C library, I tried to use extern "C" {} around the include part as below:

#extern "C" {
 #include<netcdf.h> 
}

However, I get the same errors as above. Does anyone have an idea?

MPB94
  • 153
  • 6
  • You could refer to this [link](https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file). If this link does not work, I would appreciate it if you can provide the whole path. – Barrnet Chou Jul 03 '20 at 02:51
  • *"tried something with extern "C" {} "* - what exactly did you try with this? Please be more specific in your descriptions – UnholySheep Jul 09 '20 at 09:42
  • @UnholySheep I'll edit it to be more specific. – MPB94 Jul 09 '20 at 11:06
  • There is neither the function `function` in your code nor the reference to `symbol`. Looks like you tried to strip some (private) information. But the name of the missing external symbol can be important for the question. Does it contains a decorated name or a plain `_symbol`? Did you add the name of the netcdf library to the project settings? – harper Jul 09 '20 at 11:26
  • @harper The nc_open function is supposed to be part of the netcdf library. And I used the ... in the path to indicate that there is more to the path, but I did not want to post as it contains private names. – MPB94 Jul 09 '20 at 11:34
  • What a pity, you completely misunderstood my comment. It's about the string that you name 'symbol' in the LNK2019 error message. There is no path at this position. You only inserted some ... in the path name of a kind of .nc file. That part of the example code is unrelated to LNK2019 and should be removed from the question. You can add `const char* pathPointer = "foo";` to get the same linker error. Reread: check what you added to "project properties"->Linker->Input. – harper Jul 09 '20 at 11:41
  • @harper The reason I had it incomplete, was that my settings were in german and I just translated. I now adjusted that and edited the post. You can now see the full error message. – MPB94 Jul 09 '20 at 12:15
  • @harper actually I reread what I should add in the "project properties" -> Linker->Input in the link above "Visual Studio - adding netCDF library" and added all the libraries of C:\Program Files (x86)\netCDF 4.7.4\lib there. Now it seems to work. – MPB94 Jul 09 '20 at 12:47
  • Recommendation: Put the library names to "Additional Library" but the libraries' path to "Additional Library Directories" in Linker->General of project properties. – harper Jul 09 '20 at 12:58
  • @harper Yes, this answers my question. Thank you very much. – MPB94 Jul 09 '20 at 13:28

0 Answers0