Visual Studio - adding netCDF library - c

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:
Put #include < netcdf.h >
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;
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;
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
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!

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'
(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
(still in the Linker) -> click Linker / input -> Edit 'Additional Dependencies' by adding 'netcdf.lib'.
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.

Related

cannot get MS Visual Studio VISA application to link

I am writing a test program. I am trying to do simple visa calls to instruments on USB. I cannot get the program to link - unresolved externals. At this point, my program is very simple, only a couple visa calls. I have read some content about similar problems and have tried what was suggested with out any luck.
I am using MS VisualStudio 19. I have entered the visa.h folder as C/C++ Additional Include Directory. The linker can't find any of the contained functions, such as ViOpen(). NI IVI is installed on my PC and I have added the lib folder to the VS Linker Additional Library Directories. I have also entered all the .lib files in that folder to the Linker\Input\Additional Dependencies field. But when I compile and link, I get Unresolved External Symbol errors for all the visa functions.
Folder on my PC with the lib files (there are 4 files) is...
C:\Program Files\IVI Foundation\VISA\Win64\Lib_x64\msc.
Folder on my PC with visa.h is...
C:\Program Files\IVI Foundation\VISA\Win64\Include.
Any ideas will be much appreciated.
I found the solution.
In Project Properties, changing Active Solution Platform from x86 to x64 did the trick. Now project links. Still had to add visa32.lib.

Project won't build because it can't load an assembly

Reports error on loading dll
I'm using Visual Studio 2019 Enterprise version 16.2.0
I have a dll library called RDLFunctions.dll to use in another WinForms application. Both projects are in the same solution that has worked for many years until I upgraded to Visual Studio 2019 and I can't go back. The WinForm app has about 50 reports and references the dll, but on project build, the reports that reference the dll all have similar errors (depending on which property is calling the dll).
Most research says to put the dll into several different folders:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\SSRS
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\PrivateAssemblies
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\PublicAssemblies
As well as to change values in:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\SSRS\RSPreviewPolicy.config to PermissionSetName="FullTrust"
I've deleted the file from all locations including the debug\bin directory of the dll project and rebuilt the dll. It went into the PrivateAssemblies folder automatically and I put it in the other directories. I removed/re-referenced the dll in the WinForms app, restarted the computer, etc. Nothing has helped. Everything used to work in Visual Studio 2017. I've excluded all reports in the project so it would build successfully, and it did. But when I added back even 1 report, I still got the errors.
Please help!
Here's and example of one of the error messages I get on the report "ActivityLog.rdlc"
Severity Code Description Project File Line Suppression State
Error Error while loading code module: ‘RDLFunctions,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’. Details: Could
not load file or assembly 'RDLFunctions, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null' or one of its dependencies. The
system cannot find the file
specified. Reports C:\SourceCode\Atlas\Mwells-Development-branch\Reports\Claims\ActivityLog.rdlc
copy the dll file to folder:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin
it's will work.
i'm using Visual Studio Enterprise 2019, Version 16.5.0

How to link against .a files in Visual Studio 2012?

I have some static libraries in the form of .a files, and accompanying header (.h) files. How can I tell the linker Visual Studio 2012 Windows Desktop Express to reference these files so that I don't get "unresolved external symbol" errors when I try to build?
Include the .h header files, and make sure they are present in your project
Go to Project Properties > Configuration Properties > C/C++ > General > Additional Include Directories and add the path to the include directory where your header files can be found
Go to Project Properties > Configuration Properties > Linker > General > Additional Library Directories and add the path to the lib directory where your .a files can be found
Go to Project Properties > Configuration Properties > Linker > Input > Additional Dependencies and add the .a file accurately
Apart from this make sure you are in the correct configuration platform while building (x86 vs x64) and it is same as the one your library uses.
As far as I'm aware, you can't. They're usually using a different internal binary format the linker won't be able to understand. In a similar way, MinGW won't be able to use Visual Studio's lib files (except when using an additional tool to convert them).
You'll have to recompile the library from source or obtain library files that are compatible with Visual Studio.

How to use igraph (and other libraries) in Visual Studio 2010 for C?

I just started C recently and have been writing some basic C code, but is a bit clueless about how I should go about "installing" libraries like igraph in Visual Studio 2010. I downloaded the igraph "source code for Microsoft Visual Studio" here: http://igraph.sourceforge.net/download.html
(naive) Attempt
There is an "include" folder with all the ".h" files that I copied to the directory that my Visual Studio is set up to look in whenever I use include < something.h > but I get a "unresolved external symbol", which I know means the library isn't set up correctly.
Question
How should I go about "installing" igraph? (and possibly other C libraries)
Look in to the folders of your library, I suppose, you'll find a .lib file there.
Go to your project settings and open the linker settings. Under Input you should find additional dependencies. Add your .lib file(s) there. You also might need to add the folder where this .lib file(s) reside to the library folders (found under VC++-folders).
I have the german version of MSVC here, so your menu entries might be named slightly different, but you will find them ;)
Mark's answer was very helpful, but there were other issues. Following these step resolved it for me. Hopefully this will help someone in the future.
Step 1
The igraph package is a bunch of ".c" and ".h" files that was missing the ".lib" file in Mark's answer. It has to be open and build in Visual Studio. Then, the ".lib" file will appear in the "Debug" folder.
Step 2
Do the steps in Mark's answer.
However, in "VC++ Directories" there is a line call "Include Directories" where you have to store the path to your igraph include directory. This is so that Visual Studio can find the correct files when you write e.g. #include <include/igraph.h>.
Step 3
If you get a "...already defined in MSVCRTD.lib..." error. Then, visit this answer: How to resolve the following linker errors in Visual Studio?
Each of the libraries/subprojects that you are using must be compiled with the same option in "C/C++ -> Code Generation -> Runtime library".

Reference error while compiling C file in VS2010 command-prompt

I have VS 2010 installed on my system and i was trying to compile a simple hello.c in VS command prompt. The compilation gave an error.
Fatal Error C1083: Cannot open include file: 'stdio.h' no such file, folder exist
Why this error is coming ?? Does VS2010 not include reference files/assemblies for C.
VS 2010 certainly does contain the standard headers. You should check that your command prompt environment is set up correctly. There should be an environment variable named INCLUDE that has a directory similar to the cfollowing (among other directories) in it:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE
that directory (the name may vary slightly, for example depending on if your machine is a 64-bit OS of not) should include stdio.h
If you don't have such a directory in your environment, then you're not setting up the environment correctly. You should use on of the "Visual Studio Command Prompt" shortcuts that VS installs, or simply run
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat
With the appropriate parameter to get the environment you want (x86 or amd64 for example).
If the INCLUDE environment variable does have an entry like that, but the stdio.h file doesn't exist, then you might need to reinstall VS.
I had a similar problem as the OP the VC folder was missing most of the files. I tried both repairing and uninstalling/reinstalling VS 2010 but neither worked.
What worked for me was installing the Microsoft Visual C++ 2010 Redistributable Package (x86).Microsoft Visual C++ 2010 Redistributable Package (x86)
There are so many versions of so much Windows system code that it's easy for a path to become invalid.
In my case:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include
and
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib
needed to be changed to::
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include
and
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib
i.e. v7.1A -> v7.0A (don't ask why, it just part of the everyday, tiresome task of dealing with Microsoft!).
I had the same problem. The file stdio.h did not exist in folder include. I removed VS 2010 using the Control Panel then reinstalled, but this didn't solve the problem.
I then used the VS 2010 installation CD to remove all of VS 2010, and manually removed anything leftover by Control Panel. I then installed VS 2010 professional again. The problem was solved.

Resources