1

I wonder if anyone could help me. I'm programming a NI-DAQmx application in C++, using CodeBlocks WxWidgets.

I'm using a recent version of the mingw-w64 compiler and Windows 10.

When compiling, I'm getting the undefined reference errors to the DAQmx___ statements:

`DAQmxCreateTask',

'DAQmxClearTask',

'DAQmxCreateAIVoltageChan',

and others.

I have included NIDAQmx.h, NIDAQmx.lib files in the project. I've searched for a few days, and read posts around the problem, read about wrapper files, and hacks within NIDAQmx.h, but can't seem to find anything to help.

Code snippet:

#include <math.h>
#include <limits>
#include "NIDAQmx.h"


int PxiError = 0;
TaskHandle  taskHandle=0;
float64     data[32];
char        errBuff[2048]={'\0'};
int32       readstuff;

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

double AnalogInputs(unsigned int t)
{
   // DAQmx Configure Code
    DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
    DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"PXI1Slot4/ai0:31","Voltage",DAQmx_Val_Cfg_Default, -10.0, 10.0, DAQmx_Val_Volts, NULL));

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

    // DAQmx Read Code

    //(TaskHandle taskHandle, int32 numSampsPerChan, float64 timeout, bool32 fillMode, float64 readArray[], uInt32 arraySizeInSamps, int32 *sampsPerChanRead, bool32 *reserved);
    DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,1,10.0,DAQmx_Val_GroupByChannel,data,32,&readstuff,NULL));

    //Error handling
    Error:
    if( DAQmxFailed(PxiError) )
        DAQmxGetExtendedErrorInfo(errBuff,2048);

    if( taskHandle!=0 ) {
        // DAQmx Stop Code
        DAQmxStopTask(taskHandle);
        DAQmxClearTask(taskHandle);
    }
}

Any advice would be appreciated,

Thanks,

Paul

walnut
  • 21,629
  • 4
  • 23
  • 59
Paul
  • 11
  • 6
  • When you say that you included the `.lib`, does that mean that you followed e.g. the instructions [in this question](https://stackoverflow.com/questions/5862757/how-do-i-link-to-a-library-with-codeblocks)? – walnut Nov 08 '19 at 12:49
  • What is NI-DAQmx and where did you get it for MinGW-w64? In general, binaries compiled with/for Visual Studio should not be used with MinGW-w64. – rubenvb Nov 08 '19 at 12:59
  • @uneven_mark: I added NIDAQmx.lib with it's full path to Linker settings, in Project / Build options / Linker settings tab (Both Debug and Release) – Paul Nov 08 '19 at 14:11
  • @rubenvb: I downloaded NIDAQmx.lib from the National Instruments website: https://www.ni.com/en-gb/support/downloads/drivers/download.ni-daqmx.html#325032 I'm using CodeBlocks, not Visual Studio. I downloaded the MinGW compiler, downloaded wxWidgets, then cleaned and built wxWidgets with the MinGW compiler.. – Paul Nov 08 '19 at 14:15
  • 1
    Right, but the `.lib` file you downloaded is presumable compiled with the Visual Studio compiler. You'll be in a world of pain if you continue wanting to use it with MinGW-w64 (or you may catch a lucky break hacking things together and things will work until they don't anymore). – rubenvb Nov 08 '19 at 14:17
  • That's a good point. I did get this thing working a couple of years ago, when I used the default CodeBlocks complier (GCC?) – Paul Nov 08 '19 at 14:30
  • Ok.. I tried compiling on another PC, with Widgets and compiler GNU GCC. Still the same errors appear. I've tried downloading the latest NIDAQmx.h and .lib files (64 bit), with no change. I'm a bit stuck. Some people, I've noticed mention a files called, nicaiu.dll and nilvaiu.dll. – Paul Nov 11 '19 at 12:15
  • Eventually got there.. Used NIDAQmx.lib 32 bit version. Compiled with GNU GCC. – Paul Nov 12 '19 at 09:53

1 Answers1

0

This is the compile line generated by my makefile (environment : win10/Mingw/Netbeans) : it compiles one of the examples given with the driver using gcc. (sample code copied below)

gcc -o dist/Debug/MinGW-Windows/libDAQmxIface.dll build/Debug/MinGW-Windows/DAQmxIface.o -L/C/Program\ Files
(x86)/National\ Instruments/NI-DAQ/DAQmx\ ANSI\ C\ Dev/lib/msvc -lNIDAQmx -shared

The same using g++, here is the whole netbeans output :

"/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf make.exe[1]: Entering directory /f/dev/tests/NIDAQmx_Test/DAQmxIface' "/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/libDAQmxIface.dll make.exe[2]: Entering directory /f/dev/tests/NIDAQmx_Test/DAQmxIface' mkdir -p dist/Debug/MinGW-Windows g++ -o dist/Debug/MinGW-Windows/libDAQmxIface.dll build/Debug/MinGW-Windows/DAQmxIface.o -L/C/Program\ Files\ (x86)/National\ Instruments/NI-DAQ/DAQmx\ ANSI\ C\ Dev/lib/msvc -lNIDAQmx -shared make.exe[2]: Leaving directory /f/dev/tests/NIDAQmx_Test/DAQmxIface' make.exe[1]: Leaving directory /f/dev/tests/NIDAQmx_Test/DAQmxIface'

BUILD SUCCESSFUL (total time: 2s)

Sample code provided when installing the driver :

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

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


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

    // DAQmx analog voltage channel and timing parameters

    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));

    // Stop and clear task

Error:
    if (DAQmxFailed(error))
        DAQmxGetExtendedErrorInfo(errBuff, 2048);
    if (taskHandle != 0) {
        DAQmxStopTask(taskHandle);
        DAQmxClearTask(taskHandle);
    }
    if (DAQmxFailed(error))
        printf("DAQmx Error: %s\n", errBuff);
    return 0;
}

There's a bunch of libraries in several NI directories, maybe the .lib you added to you project was not the apropriate one..

Hope it helps!

Aname
  • 515
  • 4
  • 16
  • Yes, plus I just noticed that NI's header contains #ifdef __cplusplus extern "C" { #endif Maybe it needs additional dependencies.. I'll update the answer when it works :) – Aname Aug 07 '23 at 08:51