Visual Studio - adding netCDF library

2019-05-13 20:31发布

I want to use netCDF formats in a C project using Visual Studio Express 2013 on a Windows 64bit. I've downloaded the installation file from the official website and executed the .exe.

Then, I've looked into this post to see how I should do the linking etc. More specifically, in my project in Visual Studio, I did the following:

  1. Put #include < netcdf.h >
  2. in VC++ Directories, Library directories, I added C:\Program Files (x86)\netCDF 4.3.3.1\lib; C:\Program Files (x86)\netCDF 4.3.3.1\bin;
  3. in VC++ Directories, Include directories, I added C:\Program Files (x86)\netCDF 4.3.3.1\include; C:\Program Files (x86)\netCDF 4.3.3.1\bin;
  4. in the linker>input>Additional Dependencies, I added netcdf.lib (and all other .lib files I found in the \lib folder of netCDF 4.3.3.1
  5. Placed all .dll files of the \bin folder of netCDF 4.3.3.1 in Windows\System32 and Windows\SysWOW64

However, when I run the project (F5), it gives the following 2 errors:

  • error LNK2019: unresolved external symbol_nc_strerror referenced in function _main
  • error LNK1120: 1 unresolved external --> which is, I assume, due to the first error.

I'm a almost completely new to C programming and Visual Studio. Could somebody help?

Thanks in advance!

1条回答
叼着烟拽天下
2楼-- · 2019-05-13 21:13

I finally got it working with help of others. Here are the (detailed) steps that worked for both Visual Studio 2010 as Visual Studio 2013.

I have a 64bit Windows machine, but used version 4.3.3.1 (32-bit) of the netCDF. The reason that I choose 32-bit was because 32-bit code can run on both 32- and 64-bit machines. The whole setting in general includes three parts: library installation, configure Environmental variables for your computer, and configure Properties for Visual studio.

The following are the step by step settings on my PC.

1. The netCDF library was installed at C:\Program Files (x86)\netCDF 4.3.3.1

2. Go to 'Computer', right click, and choose 'property' -> Advanced system settings -> go to 'Advanced' tab page -> click 'Environmental Variables' -> At 'System variables' field, look for a variable called 'Path', then click 'Edit' -> Append the following to the current path variables (';' is used to separate variables):

;C:\Program Files (x86)\netCDF 4.3.0\bin;

3. Go to Visual studio -> Project -> Properties -> Click 'VC++ Directories' (one of the Configuration Properties) -> Edit the value of 'Include Directories' field by adding 'C:\Program Files %28x86%29\netCDF 4.3.3.1\include' -> Edit the value of 'Library Directories' by adding 'C:\Program Files %28x86%29\netCDF 4.3.3.1\lib'

  1. (still in the Properties) Go to Linker / General (another Configuration Properties) -> make sure 'Enable Incremental Linking' field is 'No' -> Edit 'additional Library Directories' by adding the following two paths:

C:\Program Files %28x86%29\netCDF 4.3.3.1\lib C:\Program Files %28x86%29\netCDF 4.3.3.1\bin

  1. (still in the Linker) -> click Linker / input -> Edit 'Additional Dependencies' by adding 'netcdf.lib'.

  2. Properties setup done. In the C/C++ code, you just need to include netcdf library using

include

Note that for the older 4.3.0 version, other directories are also included (deps/shared). These are not listed separately anymore in the newer 4.3.3.1 version, but added directly to the \bin and \lib directories.

查看更多
登录 后发表回答