Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Undefined reference to `DAQmxCreateTask' when compiling a example program in C of NIDAQ with Visual Studio Code

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

0 Kudos
Message 1 of 4
(1,264 Views)
I am also stuck on the same point. Someone, please explain..
0 Kudos
Message 2 of 4
(1,166 Views)

Hi,

For solving this issue you need to include the header file as follows.

#include"C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\include\NIDAQmx.h"
 
After adding header file,your tasks.json file should be :
{
    "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"
}
0 Kudos
Message 3 of 4
(1,088 Views)

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.

-------------------------------------------------------
Applications Engineer | TME Systems
0 Kudos
Message 4 of 4
(1,073 Views)