From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Compiling NIDAQ C codes in DEV C

Hi,

I recently purchased a NI USB 6008 and was trying to run the  example C code for voltage sampling (\NI-DAQ\Examples\DAQmx ANSI C\Analog In\Measure Voltage\Acq-Int Clk) in Dev C++. However I got a lot of  'undefined reference' errors. I kept the NIdaqmx.h and NIdaqmx.lib in the include and library directory of the compiler but it did not improve anything. I looked into couple of  discussions in the forum about this problem but could not found a straight forward solution . It will be great if someone can point out a solution to tackle the problem. 

Thanks 

0 Kudos
Message 1 of 14
(4,302 Views)

Have you gone into your compiler’s options and explicitly pointed it toward the include folder? There’s some information on how to do this outlined in the document linked below. The steps refer to a different version of the NI-DAQ drivers, but the overall process is similar.

 

http://ae.natinst.com/public.nsf/web/searchinternal/b96d51c3f8c32f0986256f040077a386?OpenDocument

0 Kudos
Message 2 of 14
(4,278 Views)

I copy pasted the NIDaqmx.h into the include folder of dev C++ and also did the same for the NIDaqmx.lib ( into the library folder of Dev C++). It did not work. However I could not open the link you send me. Thanks for your response though. It would be great if you send an active /valid link.

0 Kudos
Message 3 of 14
(4,274 Views)

My apologies. The correct document is linked below.

 

http://digital.ni.com/public.nsf/allkb/B96D51C3F8C32F0986256F040077A386?OpenDocument

0 Kudos
Message 4 of 14
(4,272 Views)

How can I obtain nidex32.lib  and nidaqex.h. This two files were not included in the package. I am not sure if I can download them from NI website. Thanks

0 Kudos
Message 5 of 14
(4,270 Views)

nidex32.lib and nidaqex.h are part of the other NI-DAQ driver I mentioned earlier. In your case, those files would be nidaqmx.lib an nidaqmx.h, respectively.

0 Kudos
Message 6 of 14
(4,260 Views)

Can you post some of the errors, along with some of the corresponding source code? That will tell if the problem is referencing the header file or the library file.

0 Kudos
Message 7 of 14
(4,256 Views)

Here is the compiler error, the code is listed after the error log below.

Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\Makefile.win" all
gcc.exe -c "../Users/Public/Documents/National Instruments/NI-DAQ/Examples/DAQmx ANSI C/Analog In/Measure Voltage/Acq-Int Clk/Acq-IntClk.c" -o "../Users/Public/Documents/National Instruments/NI-DAQ/Examples/DAQmx ANSI C/Analog In/Measure Voltage/Acq-Int Clk/Acq-IntClk.o" -I"C:/Dev-Cpp/include" -I"C:/Program Files/National Instruments/NI-DAQ/DAQmx ANSI C Dev/include" -I"C:/Program Files/National Instruments/Shared/ExternalCompilerSupport/C/include" -I"C:/Program Files/National Instruments/NI-DAQ/DAQmx ANSI C Dev/include" -ansi -traditional-cpp
../Users/Public/Documents/National Instruments/NI-DAQ/Examples/DAQmx ANSI C/Analog In/Measure Voltage/Acq-Int Clk/Acq-IntClk.c: In function `main':
../Users/Public/Documents/National Instruments/NI-DAQ/Examples/DAQmx ANSI C/Analog In/Measure Voltage/Acq-Int Clk/Acq-IntClk.c:51: error: `int32' undeclared (first use in this function)
../Users/Public/Documents/National Instruments/NI-DAQ/Examples/DAQmx ANSI C/Analog In/Measure Voltage/Acq-Int Clk/Acq-IntClk.c:51: error: (Each undeclared identifier is reported only once

%----------------------------------------------------------------------------------------------------------------------------------

here is the code

 

#include <stdio.h>
#include <NIDAQmx.h>

 

#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else

int main(void)
{
int32 error=0;
TaskHandle taskHandle=0;
int32 read;
float64 data[1000];
char errBuff[2048]={'\0'};

/*********************************************/
// DAQmx Configure Code
/*********************************************/
DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",10000.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,1000));

/*********************************************/
// DAQmx Start Code
/*********************************************/
DAQmxErrChk (DAQmxStartTask(taskHandle));

/*********************************************/
// DAQmx Read Code
/*********************************************/
DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,1000,10.0,DAQmx_Val_GroupByChannel,data,1000,&read,NULL));

printf("Acquired %d points\n",read);

Error:
if( DAQmxFailed(error) )
DAQmxGetExtendedErrorInfo(errBuff,2048);
if( taskHandle!=0 ) {
/*********************************************/
// DAQmx Stop Code
/*********************************************/
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
}
if( DAQmxFailed(error) )
printf("DAQmx Error: %s\n",errBuff);
printf("End of program, press Enter key to quit\n");
getchar();
return 0;
}

 

 

0 Kudos
Message 8 of 14
(4,252 Views)

It looks like there is something wrong with including <NIDAQmx.h>. The error you get is with the definition of int32. That is a DAQmx typedef. Normally gcc should complain if it cannot find the include file, so maybe you are getting a broken version of NIDAQmx.h from somewhere else. Maybe a different file got renamed as NIDAQmx.h and is hiding the correct one.

 

I would try with a very small test file. Try something like this:

 

#include <NIDAQmx.h>
int main(void)
{
    int32       error=0;
    return 0;
}

If that works, add additional lines.

 

You can also tell gcc to dump the preprocessor output. If you do that, you should see the contents of NIDAQmx.h in that output. If not, something is wrong.

0 Kudos
Message 9 of 14
(4,241 Views)

I tried to run the code...below are the errors..it seems the problem is with the header file

________________________

 

Compiler: Default compiler
Executing gcc.exe...
gcc.exe "C:\Users\samik\Documents\c_practice\test.c" -o "C:\Users\samik\Documents\c_practice\test.exe" -ansi -traditional-cpp -I"C:\Dev-Cpp\include" -I"C:\Program Files\National Instruments\NI-DAQ\DAQmx ANSI C Dev\include" -I"C:\Program Files\National Instruments\Shared\ExternalCompilerSupport\C\include" -L"C:\Dev-Cpp\lib" -L"C:\Program Files\National Instruments\NI-DAQ\DAQmx ANSI C Dev\lib\msvc" -L"C:\Program Files\National Instruments\Shared\ExternalCompilerSupport\C\lib32\msvc"
In file included from C:\Users\samik\Documents\c_practice\test.c:1:
C:/Dev-Cpp/include/NIDAQmx.h:8064: warning: extra tokens at end of #endif directive
In file included from C:\Users\samik\Documents\c_practice\test.c:1:
C:/Dev-Cpp/include/NIDAQmx.h:39: error: syntax error before '/' token
C:/Dev-Cpp/include/NIDAQmx.h:77: error: syntax error before "int64"
C:/Dev-Cpp/include/NIDAQmx.h:77: warning: data definition has no type or storage class
C:/Dev-Cpp/include/NIDAQmx.h:85: error: syntax error before "uInt64"
C:/Dev-Cpp/include/NIDAQmx.h:85: warning: data definition has no type or storage class
C:/Dev-Cpp/include/NIDAQmx.h:95: error: syntax error at '#' token
C:/Dev-Cpp/include/NIDAQmx.h:95: error: syntax error before "TRUE"
C:/Dev-Cpp/include/NIDAQmx.h:98: error: syntax error at '#' token
C:/Dev-Cpp/include/NIDAQmx.h:101: error: syntax error at '#' token
C:/Dev-Cpp/include/NIDAQmx.h:2155: error: syntax error before '/' token
C:/Dev-Cpp/include/NIDAQmx.h:2224: error: syntax error before '/' token
C:/Dev-Cpp/include/NIDAQmx.h:2287: error: syntax error before '/' token
C:/Dev-Cpp/include/NIDAQmx.h:2295: error: syntax error before "uInt64"
C:/Dev-Cpp/include/NIDAQmx.h:2425: error: syntax error before '/' token
C:/Dev-Cpp/include/NIDAQmx.h:2476: error: syntax error before '/' token
C:/Dev-Cpp/include/NIDAQmx.h:2655: error: syntax error before '/' token
C:/Dev-Cpp/include/NIDAQmx.h:2749: error: syntax error before '/' token
C:/Dev-Cpp/include/NIDAQmx.h:2882: error: syntax error before '/' token
C:/Dev-Cpp/include/NIDAQmx.h:2934: error: syntax error before '/' token
Execution terminated

 

0 Kudos
Message 10 of 14
(4,236 Views)