05-26-2022 04:48 AM
Hi,
I am using an NI USB-6211 DAQ Device and I am trying to compile the following example from "C:\Users\Public\Documents\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Analog In\Measure Voltage\Acq-Int Clk".
The first thing that I did was to add the "NIDAQmx.h" file to this directory/folder because it was not included. Nevertheless, when compiling in the following way in Visual Studio Code, I have the following error:
PS C:\Users\maxim\OneDrive - Vrije Universiteit Brussel\PhD\Test Visual Studio Code\Acq-Int Clk> gcc Acq-IntClk.c -o Acq-IntClk.exe
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\maxim\AppData\Local\Temp\ccgMfeDn.o:Acq-IntClk.c:(.text+0x1bc): undefined reference to `DAQmxCreateTask'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\maxim\AppData\Local\Temp\ccgMfeDn.o:Acq-IntClk.c:(.text+0x21f): undefined reference to `DAQmxCreateAIVoltageChan'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\maxim\AppData\Local\Temp\ccgMfeDn.o:Acq-IntClk.c:(.text+0x274): undefined reference to `DAQmxCfgSampClkTiming'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\maxim\AppData\Local\Temp\ccgMfeDn.o:Acq-IntClk.c:(.text+0x296): undefined reference to `DAQmxStartTask'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\maxim\AppData\Local\Temp\ccgMfeDn.o:Acq-IntClk.c:(.text+0x301): undefined reference to `DAQmxReadAnalogF64'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\maxim\AppData\Local\Temp\ccgMfeDn.o:Acq-IntClk.c:(.text+0x45a): undefined reference to `DAQmxGetExtendedErrorInfo'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\maxim\AppData\Local\Temp\ccgMfeDn.o:Acq-IntClk.c:(.text+0x475): undefined reference to `DAQmxStopTask'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\maxim\AppData\Local\Temp\ccgMfeDn.o:Acq-IntClk.c:(.text+0x484): undefined reference to `DAQmxClearTask'
collect2.exe: error: ld returned 1 exit status.
How can I solve this problem?
Thanks,
Maxime
12-30-2022 01:29 AM
01-18-2023 05:09 AM
Hi,
For solving this issue you need to include the header file as follows.
{
"tasks": [
{
"type": "shell",
"label": "C/C++: gcc.exe build active file",
"command": "C:\\MinGW\\bin\\gcc.exe",
"args": [
"-g",
"test.c",
"-o",
"test.exe",
"-LC:\\Program Files (x86)\\National Instruments\\Shared\\ExternalCompilerSupport\\C\\lib32\\msvc",
"-lNIDAQmx"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
01-18-2023 10:19 AM
Personally, I prefer to use CMake in Visual Studio Code. It is also easier to modify it for cross-compiling for Linux. Cross-Compiling ANSI C NI-DAQmx Examples for Linux RT Using Microsoft Visual Studio Code
I have attached the CMake project with the reference configured in CMakeLists.txt. Once you have the toolchain and extension installed, CMake will generate the remaining build files.