0

I'm using Qt creator 3.5.1 to try and compile c code from a National Instruments DAQmx example.

To do this I need to include a header file "NIDAQmx.h" and link a library file "NIDAQmx.lib". Both this files are present in the project folder.

When I try to compile with msvc 2013 I get the error:

LNK1181: cannot open input file 'NIDAQmx.lib'

Searching the internet I find this is a common issue and the error code 'LNK1181' means the compiler can't find the library. But all cases presented are very specific and I couldn't find a clue to why this is not working.

Here is my .pro file:

QT += core
QT -= gui

TARGET = Test4NI
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app

SOURCES += \
    main.cpp


win32: LIBS += -L$$PWD/./ -lNIDAQmx

INCLUDEPATH += $$PWD/.
DEPENDPATH += $$PWD/.

So, the last 3 commands were added by QtCreator itself when I added the library with the wizard by right clicking the project name and selecting 'Add Library...'. I have also tried to add the path with both 'INCLUDEPATH += "$absolute path" ' and with 'LIB += "$absolute path\NIDAQmx.lib" ', but to no avail.

And below is the example code in the main.c++ file. I took the code from the orignal c example and pasted it on 'main.c++'. I don't believe this to be the source of the issue, as it is an error about library include.

#include <stdio.h>
#include "C:\BK\This\WorkEn\Qt\Test4\Test4NI\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",(int)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;
}

So you can see I include the header file with an absolute reference as it wasn't working any other way.

It seems like something silly. I've been at this for the last days.

I hope it's solved soon.

Thank you

A. Vieira
  • 1,213
  • 2
  • 11
  • 27
  • I see that you mentioned 32 bit in the title bit its not totally clear to me that your are building a 32 bit application or not. Are you building a 32 bit application? If not I believe the problem is not that windows can not find the library but the library that it finds is the wrong bitlevel. – drescherjm Nov 25 '15 at 13:53
  • Yes, I'm building a 32bit application and I've selected the 32bit version of the library provided by National Instruments. I tried other versions, but to no avail, so I used what made sense to ask the question here. I'm on a 64bit Win 10, using the kit 'Desktop Qt 5.5.1 MSVC2013 32bit', that autodetected the 32bit msvc compiler, for compiling 32bit. Also, I'm building in release mode, to avoid other issues with the library name and whatnot. – A. Vieira Nov 25 '15 at 16:48

1 Answers1

0

So I finally broke through. What follows compiled without errors.

What I did was I created a new console application for 'Desktop Qt 5.5.1 MSVC2013 32bit' kit. Then I placed the header and lib files in the project folder. I modified the main.cpp that was created on "New Project" to include the header file, and also included the lib file and header in the .pro. In the main.cpp I copied only the code lines that were relevant from the NI example I'm trying to compile.

You can check the diferences between both projects comparing the question above with the working code below. The main routine is the same, but the main function is c++ and a QCoreApplication is executed.

So, here's the .pro file:

QT += core
QT -= gui

TARGET = Test5NI
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app

HEADERS += "C:\BK\This\WorkEn\Qt\Test5\Test5NI\NIDAQmx.h"
LIBS += "C:\BK\This\WorkEn\Qt\Test5\Test5NI\NIDAQmx.lib"

SOURCES += main.cpp

And here's the main.cpp:

#include <QCoreApplication>
#include <C:\BK\This\WorkEn\Qt\Test5\Test5NI\NIDAQmx.h>

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

int main(int argc, char *argv[]){
    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",(int)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();

    QCoreApplication a(argc, argv);
    return a.exec();
}

So I guess I didn't have a proper Qt application running by not executing the last two lines of code. This makes sense.

A. Vieira
  • 1,213
  • 2
  • 11
  • 27