4

So currently I'm trying to use the VISA library from National Intruments and the IVI Foundation to read/write commands to various external devices.

I am relatively novice with my IDE: Microsoft Visual C++ Express 2010 and this is my first time trying to use a third party library that requires more than a .h import.

Basically I have a directory with 3 header files, a directory with 3 .lib libraries and a directory with 7 DLLs. They have no documentation as to what any of the individual files do, only the library as a whole. So, I need to be able to get all of these files associated with my project.

Currently I have all the headers imported in my header file and the header directory added to the include directories in the project properties. I also have the directory containing the .lib files added to the library directories in the project properties. I assumed that .lib files would link to the DLLs, but apparently that is not the case because I'm getting the error:

VISA Console 2.obj : error LNK2019: unresolved external symbol _viOpenDefaultRM@4 referenced in function _wmain

This error occurs when using any function from the library. Here is my code currently:

#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
    ViStatus status;
    ViSession defaultRM, instr;

    status = viOpenDefaultRM(&defaultRM);

    return 0;
}

The project will build when I comment out the viOpenDefaultRM command, so I assume that means I can use the objects from the library and not the commands. Since I have the 3 object declarations that build just fine.

Okay this is all my information, hopefully someone can help and hope this helps someone else!

Deduplicator
  • 41,806
  • 6
  • 61
  • 104
jjno91
  • 573
  • 5
  • 17

2 Answers2

5

In addition to having the directory for the .lib file(s) added to the library directories property, you need to also add the actual libraries that the linker should search.

Add the libraries to the project's

 Configuration Properties | Linker | Input | Additional Dependencies

field.

The DLLs are not necessary for the build process, but to run the program they should be in a directory inthe PATH or in the same directory as the program file.

Michael Burr
  • 311,791
  • 49
  • 497
  • 724
  • also make sure you use the correct path: Visa supplies both 32 and 64 bit versions of their libs; since the Visa installer creates the VXIPNPPATH and VXIPNPPATH64 environment variables it's best to use them instead of hardcoding paths. – stijn Dec 20 '12 at 17:00
  • @stijin Sorry, yes I have added the files to the additional dependencies. I added the 3 .lib files' full paths to it, but it doesn't look like the other .lib files in the dialog box. All the others dropped the full file path whereas mine still have theirs, and mine are not showing up in the external dependencies folder. – jjno91 Dec 20 '12 at 17:02
  • @stijn Okay, so I changed the additional dependencies to $(VXIPNPPATH64) and it changed the error message to: LINK : fatal error LNK1104: cannot open file 'C:\Program Files\IVI Foundation\VISA\\.obj' Could this mean there is something wrong with the environmental variable? – jjno91 Dec 20 '12 at 17:26
  • you don't have to use just VXIPNPPATH but something like $(VXIPNPPATH)\winnt\lib, I don't know by hart, you can figure it out easily by looking for the correct subdirectory in explorer – stijn Dec 20 '12 at 18:08
  • @stijn Thanks so much. I got it figured out. Apparently you don't need the library directory at all. I just needed the include directory set to: C:\Program Files %28x86%29\IVI Foundation\VISA\WinNT\include and the linker additional dependencies set to: "$(VXIPNPPATH)WinNT\lib\msc\visa32.lib" now this is for 32-bit, I haven't gotten it working for 64-bit, but this is all I need. Thanks again, hope this saves someone else some time! – jjno91 Dec 20 '12 at 19:42
1

Have you added to the project properties the additional dependecies?

Under "Linker->Input" find "Additional Dependecies" and place there the libs that you got from

João Augusto
  • 2,231
  • 25
  • 27
  • Sorry, yes I have added the files to the additional dependencies. I added the 3 .lib files' full paths to it, but it doesn't look like the other .lib files in the dialog box. All the others dropped the full file path whereas mine still have theirs, and mine are not showing up in the external dependencies folder. – jjno91 Dec 20 '12 at 17:06