I'm more a c++ rookie. I want to create a dll using visa. I simplified the problem to an exe example. I've got the following MnWE:
#include <cstdlib>
#include <sstream>
#include <string>
#include <iostream>
#include <stdio.h>
#include <stdexcept>
#include <windows.h>
#include "visa.h"
using namespace std;
ViSession defaultRM = 0;
//opens VI-Session in specific address. Puts the defaultRM stuff "away".
void openVI (char* adress, ViSession vi, string mode, int timeout){
if(defaultRM == 0){
viOpenDefaultRM(&defaultRM);// Initialize VISA system
if(defaultRM==0){
cerr << "initalizing defaultRM failed";
}else{
cout << "defaultRM initalized";
}
}else{
}
ViAccessMode viMode = VI_NULL;
ViUInt32 viTimeout = VI_NULL;
if(mode == "EXCLUSIVE"){
viMode = VI_EXCLUSIVE_LOCK;
viTimeout = timeout;
}else if(mode == "DEFAULT"){//Code für default kann hier eingefügt werden. Derzeit nichts vorgesehen.
}else{
}
viOpen(defaultRM, adress, viMode, viTimeout, &vi);
}
int main(){
ViSession vi;
openVI("ASRL2::INSTR", vi, "DEFAULT", 0);
if(vi = 0){
cout << "failed" << endl;
}else{
cout << "success" << endl;
}
return 0;
}
When compiling with gcc and the command
g++ -static -o VITest.exe VITest.cpp
I get the following error:
F:\Users\gabriel\AppData\Local\Temp\ccEx2dRK.o:VITest.cpp:(.text+0x17): undefined reference to `viOpenDefaultRM@4'
F:\Users\gabriel\AppData\Local\Temp\ccEx2dRK.o:VITest.cpp:(.text+0xbd): undefined reference to `viOpen@20'
collect2.exe: error: ld returned 1 exit status
As far as my gooleing brought me, it seems to have to do with the linking to the libs. I dont have the agilent-visa distribution on my pc yet. I just put the visa.h, visadef.h and visa.lib into the same folder as the cpp-file. I suppose, that it might have to with that. But I only want to install it, when definitely necessary. The final program will run on another machine.