1

I am developing a Windows (7) application using Qt (4.7.0) to call some methods in a DLL (NI visa32.dll) to communicate with instruments through the GPIB port. The manufacturer's header file is also available (visa.h).

In the project file, I tried adding the path and library reference to the original places where the files are located at as:

INCLUDEPATH += "C:/Program Files/National Instruments/Shared/CVI/Include"  
LIBS        += "C:/Windows/System32/visa32.dll"

but, I get the compilation error:

collect2: ld returned 1 exit status

Following the instructions in Importing a DLL into Qt, I created a "visa.a" from the "visa32.dll", and copied them to a subfolder "visa/lib", and added the path and library to the project file:

INCLUDEPATH += visa/include  
LIBS        += -Lvisa/lib  
LIBS        += -lvisa.a

I tried also with -lvisa or -lvisa.dll, but in all the cases I get also another compilation error saying that the -lvisa, -lvisa.a or -lvisa.dll is not found. I edited the original header file "visa.h", and prefixed with Q_DECL_IMPORT every object in the file, and also made sure that the extern "C" statement be present.

I include the reference to the header file in the application as:

#include "visa.h"

and note that the compiler does recognize the referenced objects belonging to the visa.h file.

Any help to solve this compilation error will be greatly appreciated.


I also tried with Visual C++ (2010) following the instructions of DLL References in Visual C++. In this case, I do not get any compilation error, but linking errors. For example:

AgiE364X.obj: error LNK2019: unresolved external symbol  
"extern "C" long __stdcall viClose(unsigned long)"  

being viClose a called method in NI-VISA.

I would prefer to use Qt C++ instead of Visual C++, though.

Thanks in advance.

Community
  • 1
  • 1
Fabio
  • 11
  • 1
  • 3

2 Answers2

0

There are two types of library of VISA provided by NI: the one is compiled by borland c++, the other is compiled by microsoft vc++.

As for Qt, you can use Qt which should be compiled by MSVC, to link the visa32.lib which is compiled by MSVC too. And it MUST link .lib instead of .dll, The MSVC library of VISA is in "C:\Program Files\IVI Foundation\VISA\WinNT\lib\msc" by default.

The include directory is C:\Program Files\IVI Foundation\VISA\WinNT\include by default.

In fact, the above information can be known from VISA example after you install the device driver.

Tody.Lu
  • 915
  • 9
  • 24
0

I'm not sure since I'm new to Qt myself but here are some guesses: I noticed you have a space in INCLUDEPATH string. Also, LIBS += -Lvisa/lib has a capitol L (is this correct?). I'm not saying this is your problem but perhaps worth a try. The last thing that comes to mind is that if you're using Qt Creator only partially type #include "visa.h" and see if auto complete can complete it for you. If it can, than prob the rest is OK. Trigger auto-complete with Ctrl+Space. I've noticed that when I mess up the paths auto-complete is a good gauge for this sort of thing.

user440297
  • 1,181
  • 4
  • 23
  • 33
  • Hi. Thanks for your answer. 1. In my first try I use INCLUDEPATH += "C:/Program Files/National Instruments/Shared/CVI/Include" – Fabio Feb 16 '11 at 23:19
  • Hi. Thanks for your answer. 1. In my first try I use INCLUDEPATH += "C:/Program Files/National Instruments/Shared/CVI/Include" but the space is taken care by using quotes. 2. In my second try, I use LIBS += -Lvisa/lib and the capital L indicates the library path. In contrast, lowercase l indicates the library name. 3. The include statement is correct. When I am typing it, the drop-down menu shows up visa.h. Still I get the same compilation error: collect2:Id returned 1 exit status – Fabio Feb 16 '11 at 23:32
  • Ahh. That sounds familiar. I can't quite remember... but I think i saw that error when trying to compile while a previous running instance of your app (command line console) is open. Make sure you close console before try to compile. Not sure if you use Qt creator built in console. In that case may need to hit the stop button (red square). There is an option in Qt Creator to set console output to actual system console. That is a good option to select as not everything gets put out to built in console properly anyway. If making a GUI app I think same still holds, make sure app is closed. – user440297 Feb 17 '11 at 01:37
  • Also, I think it is possible that something is calling some functions that it thinks should exist, but which may not. Maybe the lib you're linking is not enough..that is to stay, not stand alone and it needs something more to work. A dependency issue? Maybe it assumes MS visual Studio env. Try adding #include also. – user440297 Feb 17 '11 at 01:45
  • Hi user440297. Regarding Qt, I am using Qt Creator (2.0.1). The application has a user interface. No command line console is open during any compilation attempt. Regarding Visual C++, I added the Windows.h include statement, but still I get the same linking errors. Thanks. – Fabio Feb 17 '11 at 23:53