Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

NI-DAQmx 8.0.1 undefined reference

Solved!
Go to solution

Hi,

 

I am new to using NI-DAQmx on Linux. After reading through the posts in this forum, I have been able to succesfully install NI-DAQmx 8.0.1 on OpenSUSE 11.0. When running 'nilsdev', I get the following list of devices:

NI PXI-6255: "Dev4"
NI PXI-6733: "Dev3"
NI PXI-6733: "Dev2"
NI PXI-6713: "Dev1"

 

Which is correct. However, when trying to compile the following sample program using "gcc main.c":

#include "NIDAQmx.h"
#include <stdio.h>
#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else
int main(void) {
    int error = 0;
    TaskHandle taskHandle = 0;
    char errBuff[2048] = {'\0'};
    float64 data[3] = {1.0,2.0,3.0};
    /*********************************************/
    // DAQmx Configure Code
    /*********************************************/
    DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
    DAQmxErrChk (DAQmxCreateAOVoltageChan(taskHandle,"PXI1Slot4/ao0:2","",-10.0,10.0,DAQmx_Val_Volts,""));
    /*********************************************/
    // DAQmx Start Code
    /*********************************************/
    DAQmxErrChk (DAQmxStartTask(taskHandle));
    /*********************************************/
    // DAQmx Write Code
    /*********************************************/
    DAQmxErrChk (DAQmxWriteAnalogF64(taskHandle,1,1,10.0,DAQmx_Val_GroupByScanNumber,data,NULL,NULL));
Error:
    if( DAQmxFailed(error) )
        DAQmxGetExtendedErrorInfo(errBuff,2048);
    if( taskHandle!=0 ) {
        /*********************************************/
        // DAQmx Stop Code
        /*********************************************/
        DAQmxStopTask(taskHandle);
        DAQmxClearTask(taskHandle);
    }
    if( DAQmxFailed(error) )
        printf("Error");
    getchar();
    return 0;
}

 

I obtain several errors regarding undefined references:

main.c:(.text+0x90): undefined reference to `DAQmxCreateTask'
main.c:(.text+0xdc): undefined reference to `DAQmxCreateAOVoltageChan'
main.c:(.text+0xf0): undefined reference to `DAQmxStartTask'
main.c:(.text+0x140): undefined reference to `DAQmxWriteAnalogF64'
main.c:(.text+0x15f): undefined reference to `DAQmxGetExtendedErrorInfo'
main.c:(.text+0x171): undefined reference to `DAQmxStopTask'
main.c:(.text+0x17c): undefined reference to `DAQmxClearTask'

 

I previously installed NI-DAQmx on a WindowsXP machine, and obtained the same errors, but was able (using this post) to create the necessary libraries to link against. However, I have not found any similar information to do this on Linux (this post seemed to include this problem, but unfortunately the originator did not share his solution). So far, I have tried various linking options with no succes "-ldl", etc. Obviously, I'm not linking correctly.

 

Any help would be greatly appreciated.

 

Thanks,

Grine

0 Kudos
Message 1 of 7
(5,983 Views)
Solution
Accepted by topic author ermkms

I solved the linking step. (Why do answers always come when you've almost given up? :p)

As I suspected, a simple linking issue. Compiling with "gcc main.c /usr/local/lib/libnidaqmx.so -o main" did the trick.

I still have some errors when running the program, but I can probably solve these on my own.

0 Kudos
Message 2 of 7
(5,978 Views)

Glad you were able to figure out the link errors by pointing to the DAQmx library.

 

One issue that I see looking at the code you're using (but you might have figured out by now) is that the device name used in DAQmxCreateAOVoltageChan says PXI1Slot4, but you say that you have "Dev1", "Dev2", "Dev3", and "Dev4".  If you change that to something like, "Dev1/ao0:2", I wouldn't expect any other problems running that code (that is, it looks correct).

Thanks,

Andy McRorie
NI R&D
0 Kudos
Message 3 of 7
(5,961 Views)

Also, I'm pretty sure that the DAQmx examples ship with a make file.  The make file should give you the flags you need to provide to gcc.

 

Neil S.

0 Kudos
Message 4 of 7
(5,924 Views)

Maybe a am refreshing the old theme, but still.

 

I am experimenting in programming c program, which will do DI/DO/AI/AO.

I found examples in NI-DAQ folder.

 

These examples do not run, so i went through the errors and tried to fix them.

Still, i have some problems.

 

- I had to change declaration of main function that way, that it is integer (int) and returns nothing, not void (dev-c++ wanted this from me, otherwise error)

- My errors are:

C:\Program Files\National Instruments\NI-DAQ\Examples\VisualC\Do\DOoneLine.C In function 'int main()':
74 20 C:\Program Files\National Instruments\NI-DAQ\Examples\VisualC\Do\DOoneLine.C [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
81 20 C:\Program Files\National Instruments\NI-DAQ\Examples\VisualC\Do\DOoneLine.C [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
C:\Program Files\National Instruments\NI-DAQ\Examples\VisualC\Do\DOoneLine.o DOoneLine.C:(.text+0x6d): undefined reference to `DIG_Line_Config@16'
C:\Program Files\National Instruments\NI-DAQ\Examples\VisualC\Do\DOoneLine.o DOoneLine.C:(.text+0x90): undefined reference to `NIDAQErrorHandler@12'
C:\Program Files\National Instruments\NI-DAQ\Examples\VisualC\Do\DOoneLine.o DOoneLine.C:(.text+0xdf): undefined reference to `DIG_Out_Line@16'
C:\Program Files\National Instruments\NI-DAQ\Examples\VisualC\Do\DOoneLine.o DOoneLine.C:(.text+0x102): undefined reference to `NIDAQErrorHandler@12'
C:\Program Files\National Instruments\NI-DAQ\Examples\VisualC\Do\DOoneLine.o DOoneLine.C:(.text+0x127): undefined reference to `NIDAQWaitForKey@8'
C:\Program Files\National Instruments\NI-DAQ\Examples\VisualC\Do\DOoneLine.o DOoneLine.C:(.text+0x176): undefined reference to `DIG_Out_Line@16'
c:\program files\dev-cpp\mingw32\mingw32\bin\ld.exe ../National Instruments/NI-DAQ/Examples/VisualC/Do/DOoneLine.o: bad reloc address 0x20 in section `.eh_frame'
c:\program files\dev-cpp\mingw32\mingw32\bin\ld.exe final link failed: Invalid operation
C:\Program Files\Dev-Cpp\collect2.exe [Error] ld returned 1 exit status
25 C:\Program Files\Dev-Cpp\Makefile.win recipe for target 'Projekt1.exe' failed

 

- Two functions mention some conversion to char, i dont know what that means.

- There are some undefined reference errors, i assume that compiler doesnt recognize functions. I found this error explanation on the ni website: http://digital.ni.com/public.nsf/allkb/B96D51C3F8C32F0986256F040077A386

I did all the steps, added tho lib files in my project (i think i had just to add them along the .c file), i included .h headers into .c code, i modified settings of compiler, that i included Lib alongside Library folders and include folder alongside both C and C++ inclusions.

Still have errors.

 

Code:

 

#include "C:\Dev-Cpp\include\nidaqex.h"
#include "C:\Dev-Cpp\include\nidaq.h"
/*
* Main:
*/

int main()
{
/*
* Local Variable Declarations:
*/

i16 iStatus = 0;
i16 iRetVal = 0;
i16 iDevice = 1;
i16 iPort = 0;
i16 iLine = 0;
i16 iDir = 1;
i16 iStateON = 1;
i16 iStateOFF = 0;
i16 iIgnoreWarning = 0;

/* Configure line as output. */

/* NOTE: Some devices do not support DIG_Line_Config. Use
DIG_Prt_Config instead. */

iStatus = DIG_Line_Config(iDevice, iPort, iLine, iDir);

iRetVal = NIDAQErrorHandler(iStatus, "DIG_Line_Config",
iIgnoreWarning);

printf(" The digital state on port %d line %d is set to %d\n", iPort, iLine, iStateON);

iStatus = DIG_Out_Line(iDevice, iPort, iLine, iStateON);

iRetVal = NIDAQErrorHandler(iStatus, "DIG_Out_Line",
iIgnoreWarning);

printf(" Hit any key to change it to %d\n", iStateOFF);

iRetVal = NIDAQWaitForKey(0.0);

printf(" The digital state on port %d line %d is set to %d\n", iPort, iLine, iStateOFF);

iStatus = DIG_Out_Line(iDevice, iPort, iLine, iStateOFF);

return 0;
}

/* End of program */

 

Device, port... are properly numerered in variable declarations.

 

Thanks for the answer,

akos3

 

P.s: Modifying and adding .MAK file only makes more errors.

0 Kudos
Message 5 of 7
(5,301 Views)

Hi, 

 

I am using an example program from    \NI-DAQ\Examples\DAQmx ANSI C for writing to port a NI PXIe-6738 DAQ board. Using it in Dev-Cpp in windows 10 (64 bit) OS.  "NIDAQmx.h" is included .

 

Encounterd the same problems i.e. 

 

WriteDigPort.c:(.text+0x5b): undefined reference to `DAQmxCreateTask'

WriteDigPort.c:(.text+0x93): undefined reference to `DAQmxCreateDOChan', etc...

 

How to solve these. What are the linking parameters, Thanks in advance

 

Regards

 

 

 

0 Kudos
Message 6 of 7
(3,649 Views)

Hi, 

 

I'm having the exact same issue. Can you tell us what exactly you did, when you did:

 

Compiling with "gcc main.c /usr/local/lib/libnidaqmx.so -o main"

 

Thanks, 

 

Paul

0 Kudos
Message 7 of 7
(3,450 Views)