05-18-2017 03:41 PM
I am new to VirtualBench and I saw that there is a C API but cannot find much about it online or any documentation. Maybe I am just looking in the wrong place. I have the latest driver installed on my machine. Is there an example program and documentation somewhere? Thanks!
05-18-2017 06:22 PM - edited 05-18-2017 06:22 PM
Hi Ejo,
If you install ANSI C support during the NI-VirtualBench driver install, after the install completes you should find a VirtualBench C Reference Help.chm at C:\Users\Public\Documents\National Instruments\VirtualBench Documentation as well as example programs at C:\Users\Public\Documents\National Instruments\VirtualBench ANSI C Examples.
If you don't see these files currently, you can go to Control Panel >> Programs and Features >> National Instruments Software, find the VirtualBench ADE Support, and do a modify install.
Hope that helps!
05-22-2017 07:49 AM
Thank you, I found the examples, but I am having trouble getting them to compile. Can you point me to the location of the nivirtualbench.h file?
05-22-2017 08:34 AM
I have found the nivirtualbench.h file under C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C
But I still cannot get the example to compile, specifically, niVB_Dig_Example.c
I created a new project in eclipse, pointed it to the correct .h files now, but I am still getting this error:
relocation truncated to fit: R_X86_64_PC32 against undefined symbol `niVB_Dig_Close' niVB_Dig_Example line 0 C/C++ Problem
I also tried the niVB_Dig_Example_utf16.c, but I don't have the windows.h file for that example.
05-22-2017 10:02 AM
You'll also need to link against the import library. I'm not an Eclipse user, so I don't know where specifically in the project options this needs to go (somewhere related to "linker options" probably?), but you'll need to add one of the following:
For the *_utf16.c examples, windows.h is part of the Windows SDK.
05-22-2017 12:49 PM
I think I am linking the libs correctly, but I am still receiving those errors. Below are the actual commands that are getting run from eclipse:
make all Building file: ../src/niVB_Dig_Example2.c Invoking: Cross GCC Compiler gcc -I"C:\cygwin64\usr\include" -I"C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\include" -O0 -g3 -Wall -c -fmessage-length=0 -mcmodel=medium -fPIC -MMD -MP -MF"src/niVB_Dig_Example2.d" -MT"src/niVB_Dig_Example2.o" -o "src/niVB_Dig_Example2.o" "../src/niVB_Dig_Example2.c" ../src/niVB_Dig_Example2.c:1:0: warning: -fPIC ignored for target (all code is position independent) /****************************************************************************** ^ ../src/niVB_Dig_Example2.c: In function 'main': ../src/niVB_Dig_Example2.c:98:17: warning: format '%d' expects argument of type 'int', but argument 2 has type 'size_t {aka long unsigned int}' [-Wformat=] printf("Iteration %d:\n", i); ^ ../src/niVB_Dig_Example2.c:98:17: warning: format '%d' expects argument of type 'int', but argument 2 has type 'size_t {aka long unsigned int}' [-Wformat=] Finished building: ../src/niVB_Dig_Example2.c Building target: niVB_Dig_Example2.exe Invoking: Cross GCC Linker gcc -L"C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc" -o "niVB_Dig_Example2.exe" ./src/niVB_Dig_Example2.o -lnisyscfg -lnivirtualbench C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b):(.text+0x2): relocation truncated to fit: R_X86_64_32 against symbol `__imp_niVB_Initialize' defined in .idata$5 section in C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b) C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b):(.text+0x2): relocation truncated to fit: R_X86_64_32 against symbol `__imp_niVB_Finalize' defined in .idata$5 section in C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b) C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b):(.text+0x2): relocation truncated to fit: R_X86_64_32 against symbol `__imp_niVB_GetExtendedErrorInformation' defined in .idata$5 section in C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b) C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b):(.text+0x2): relocation truncated to fit: R_X86_64_32 against symbol `__imp_niVB_GetErrorDescription' defined in .idata$5 section in C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b) C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b):(.text+0x2): relocation truncated to fit: R_X86_64_32 against symbol `__imp_niVB_Dig_Initialize' defined in .idata$5 section in C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b) C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b):(.text+0x2): relocation truncated to fit: R_X86_64_32 against symbol `__imp_niVB_Dig_Write' defined in .idata$5 section in C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b) C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b):(.text+0x2): relocation truncated to fit: R_X86_64_32 against symbol `__imp_niVB_Dig_Read' defined in .idata$5 section in C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b) C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b):(.text+0x2): relocation truncated to fit: R_X86_64_32 against symbol `__imp_niVB_Dig_Close' defined in .idata$5 section in C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b) collect2: error: ld returned 1 exit status make: *** [makefile:32: niVB_Dig_Example2.exe] Error 1
05-22-2017 04:06 PM
Sorry, those were not the same errors as before, these are new "relocation truncated to fit" errors, which I think indicates either a linking issue or trying to store some very large data in the program, or maybe something else.
05-24-2017 08:31 AM
Is it possible for NI to provide a complete working Solution file (for visual studio), a Makefile, or even just the gcc commands used to compile and link the examples properly? I am having a tough time getting this to work with our new VirtualBench.
05-24-2017 04:48 PM - edited 05-24-2017 04:53 PM
Apologies for the delay; I'd been tied up with NIWeek.
Attached is an example project I built with MSVC2017. I built this with the following steps:
I think these steps should be roughly the same for older versions of MSVC.
I also ran into the same format-string warnings you saw when building for 64-bit; when the examples were first made, the current version of MSVC didn't support format-string checking, so we missed that. I filed CAR 648920 for us to update the example to use the correct format string specifiers.
05-25-2017 03:54 PM
Thank you for the complete project, it worked right away and I see where I went wrong now. I was able to modify some of the examples to do what I need with the VB. I don't have much experience with Visual Studio or MSVC, so this was a big help. I think it would be beneficial to others to have a sample project like that bundled with the API.