Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

C Code NI-VISA linker error

Solved!
Go to solution

I wrote the following C command to pass SCPI commands to Rohde&Schwarz FSL

 

#define NIVISA_PXI
#include <visa.h>
#define MAX_CNT 200
int main(void)
{
ViStatus status; /* For checking errors */
ViSession defaultRM, instr; /* Communication channels */
ViUInt32 retCount; /* Return count from string I/O */
ViChar buffer[MAX_CNT]; /* Buffer for string I/O */
status = viOpenDefaultRM(&defaultRM);
if (status < VI_SUCCESS)
return -1;
status = viWrite(instr, "*RST", 6, &retCount);
status = viClose(instr);
status = viClose(defaultRM);
return 0;
}

 

I am getting linker errors.   [Linker error] undefined reference to `viOpenDefaultRM@4' 

 

I use Bloodshed Dev C++ . I have included the header files from the VXIPNP folder to the include folder od Dev C++. It had 11 files.it had 4 header files visa.h, visatype.h, vpptype.h and rsfsp.h

 

Do i need to install any header file or libraries? Please help, this is the first time I am using VISA.H 

 

 

 

 

 

 

 

0 Kudos
Message 1 of 8
(12,245 Views)

hi rohit_rs,

 

I recommend you to use the RsSpecAn Instrument driver. There is already an example for LW/CVI on the driver download page available and correct setup ot the development environment is described inside the How To Use pdf file. (all the things you wrote in your post are encapsulated in one call: rsspecan_init(...)) 😉

 

regards juergen

 

ps.  to your problem: have you "told" your linker where the visa dll is?

Message 2 of 8
(12,243 Views)
Solution
Accepted by topic author rohit_rs

excuse my ignorance...but i have never worked with .dll in C++ can u please elaborate how do i tell my linker where the 'visa.dll' file is.

 

Thnks

0 Kudos
Message 3 of 8
(12,240 Views)

I figured it nw. Thanks a lot

0 Kudos
Message 4 of 8
(12,233 Views)
hey, the code is working fine nw....but i have one more query...if i want to port it to linux wat library file should i use?...libvisa.so (i used visa32.lib for windows)
0 Kudos
Message 5 of 8
(12,191 Views)
I think the library has the same name, but I'm not sure. regards.
0 Kudos
Message 6 of 8
(12,159 Views)

Yes it is libvisa.so for linux.

 

Regards,

 

vaibhav

 

.......^___________________^
....../ '---_BOT ____________ ]
...../_==O;;;;;;;;_______.:/
.....),---.(_(____)/.....
....// (..) ),----/....
...//____//......
..//____//......
.//____//......
..-------
0 Kudos
Message 7 of 8
(12,140 Views)

[root@localhost raavan]# gcc main.c -L /usr/local/lib/libvisa.so

 

/tmp/ccKHyQta.o: In function `sendscpi':
main.c: (.text+0x2e): undefined reference to `viWrite'
/tmp/ccKHyQta.o: In function `main':
main.c: (.text+0x52): undefined reference to `viOpenDefaultRM'
main.c: (.text+0x99): undefined reference to `viOpen'
main.c: (.text+0xbb): undefined reference to `viSetAttribute'
main.c: (.text+0xd9): undefined reference to `viClose'
main.c: (.text+0xeb): undefined reference to `viClose'
collect2: ld returned 1 exit status

 

 

 

contents of main.c are:

 

 #include "visa.h"
#include "stdio.h"
#include "string.h"
#define MAX_CNT 200
 
char scpi[50]; /*To store the SCPI commands*/
ViStatus status; /* For checking errors */
ViSession defaultRM, instr; /* Communication channels */
ViUInt32 retCount; /* Return count from string I/O */
ViChar buffer[MAX_CNT]; /* Buffer for string I/O */
 
void sendscpi (char *s)  
{
     status = viWrite(instr, (ViBuf)s, strlen (s), &retCount);
      
}
 
int main(void)
{
/* Begin by initializing the system*/
status = viOpenDefaultRM(&defaultRM);
if (status < VI_SUCCESS) {
return -1;
}
/* Open communication with TCPIP Device at Primary Addr FSL (192.168.186.107)*/
 
status = viOpen(defaultRM, "192.168.186.107", VI_NULL, VI_NULL,&instr);
/* Set the timeout for message-based communication*/
status = viSetAttribute(instr, VI_ATTR_TMO_VALUE, 5000);
/* Send SCPI commands for the test case */
sendscpi ("*RST" ) ;
/* Close down the system */
status = viClose(instr);
status = viClose(defaultRM);
return 0;
}

 

 

Please help!

Message Edited by rohit_rs on 03-12-2009 07:04 AM
Message Edited by rohit_rs on 03-12-2009 07:04 AM
0 Kudos
Message 8 of 8
(12,101 Views)