Multifunction DAQ

Showing results for 
Search instead for 
Did you mean: 

How Can I Use The NI-DAQmx ANSI C Function Library With GCC (on Windows)?

Thank you everybody for the very useful suggestions. I am using msys gcc on windows XP.
Has anyone tried to compile the analog output examples? I manage to compile and execute the analog input examples with no problems following the detailed expanation found here but when I try the analog output examples I get this error from gcc:

$ gcc ContGen-IntClk-AnlgStart.c -o ContGen-IntClk-AnlgStart.exe "C:\Program Fi
les\National Instruments\NI-DAQ\DAQmx ANSI C Dev\lib\libnidaqmx.a" -I "C:\Progr
am Files\National Instruments\NI-DAQ\DAQmx ANSI C Dev\include"
In file included from ContGen-IntClk-AnlgStart.c:53:
C:/Program Files/National Instruments/NI-DAQ/DAQmx ANSI C Dev/include/NIDAQmx.h: 77: error: syntax error before "int64"
C:/Program Files/National Instruments/NI-DAQ/DAQmx ANSI C Dev/include/NIDAQmx.h: 77: warning: data definition has no type or storage class
C:/Program Files/National Instruments/NI-DAQ/DAQmx ANSI C Dev/include/NIDAQmx.h: 85: error: syntax error before "uInt64"
C:/Program Files/National Instruments/NI-DAQ/DAQmx ANSI C Dev/include/NIDAQmx.h: 85: warning: data definition has no type or storage class
and so on for many other lines. in NIDAQmx.h

can anyone help?
Thank you

0 Kudos
Message 21 of 43
Simple solution:

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

in the example .c file.

Complex solution:

hack NIDAQmx.h to do something smarter than
#ifdef __linux__
when creating 64 bit typedefs.
Message 22 of 43
everything works fine now.

0 Kudos
Message 23 of 43
Hello everybody,
I encountered another problem.
I am using Msys gcc on win XP to compile custom c code.
I manage to compile and run the examples no problem, linking fine, Analog I/O working.

I get segfault error when calling
DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
but I can call functions such as:
DAQmxErrChk (DAQmxGetExtCalLastDateAndTime ("Dev1",&year,&month,&day,&hour,&minute));
DAQmxErrChk (DAQmxResetDevice ("Dev1"));
without any problems and get sensible output.
Does anyone know if there is any particular precaution when doing task creation?
how is the memory allocated by CreateTask?
are there any particular compiler options that should not be used?

Thank you

0 Kudos
Message 24 of 43
more info on the problem just reported:
What I am trying to do is to compile a nidaqmx code (say for example one of the analog output examples) into a dll and then dynamically load that into the custom software we use in the lab.
Compilation and linking with libnidaqmx.a obtained following the instructions in this forum are both successful.
I am able to load the generated dll into the main software but when the function:
is called, I get segfault.

I tried recompiling the main program from source, including my code linked statically and it works fine, so it is something due to the fact that I am trying to compile the nidaqmx code into a dll.

anyone has had a similar problem?


0 Kudos
Message 25 of 43
If you added UnixUtils to your PATH enviroment variable, REMOVE IT ! Otherwise, gcc/g++ is confused with / and \ in file paths.

I lost 1 day on that !
0 Kudos
Message 26 of 43
Hello all,
this is a short message to say that after two weeks of test I have not yet solved the problem. Has anyone encountered a similar problem?
short summary:
I am using mingw gcc on win XP. Followed all instructions to obtain libnidaqmx.a (actually I did not even install unxutils, I just needed "sed" from gnuwin32 to run the script).
I manage to succesfully compile and execute the examples included with nidaqmx.
I manage to sucessfully compile and execute custom nidaqmx code.
now I need to create a dll plug-in with the following command:

gcc  -o ../../bin/nidaqmx6229.dll -mwindows -shared -L../../lib  -L./lib/. ./obj/nidaqmx6229.o "C:\Program Files\National Instruments\NI-DAQ\DAQmx ANSI C Dev\lib\libnidaqmx.a" -lalleg -lxvin -Wl,--export-all-symbols  -Wl,--enable-auto-import -Wl,--out-implib=./lib/libnidaqmx6229.a

which creates a dll that I can then load into a main software. This is a custom software we use in our laboratory and it is all written in ANSI C.
The command executes correctly, and it creates the requested dll.
Nevertheless, when I try to execute some nidaqmx function called from this dll I get segfault.
As a check I recompiled the whole software, linking my plug-in as a static object and it works fine. So the problem must be due to the fact that I am trying to build a dll, or that I am not building it correctly.
Any suggestion is appreciated.



0 Kudos
Message 27 of 43
Hi Francesco,

I am doing something similar. In my case I am wrapping nidaqmxbase.dll in another dll for access from Java (JNI). After doing everything outlined in dplamp's reply (#14), this is gcc command line that is working fine for me:

gcc -mno-cygwin -Wl,--add-stdcall-alias -I"C:\Program Files\Java\jdk1.5.0_06\jreinclude" -I"C:\Program Files\Java\jdk1.5.0_06\include\win32" -I"C:\Program Files\National Instruments\NI-DAQmx Base\Include" -L"C:\Program Files\National Instruments\NI-DAQmx Base\Lib" somefile.c -lnidaqmxbase -shared -o mydaqmxbase.dll

The -mno-cygwin is just so that I don't depend on cygwin1.dll. The -lnidaqmxbase (or libdaqmxibase.a) is the library prepared using instructions and scripts from dmplam's earlier reply. The -add-stdcall-alias is the trick that makes it work (see stadel's earlier reply #5 and also good overview from David Caldwell). Naturally, if you are not building JNI code you should remove related -I"..Java.." arguments.

I hope that this will help...


0 Kudos
Message 28 of 43
Hello Vladimir,
Thanks a lot for the reply. I tried adding the -Wl,--add-stdcall-alias option, but it got no better. Maybe I misunderstood stadel's explanation, but I thought that was related to the fact that, at compile time, gcc could not link proberly because it was not finding the right names and decorations. In my case, I am able to build a dll without any problem, the problem is when I try to execute a function contained in it. I tried installing dr. mingw to have debugging information about the segfault but I got no better either. this is the response I get:
xvin.exe caused an Access Violation at location 64019d9a Reading from location 64019d9a.

eax=00000001 ebx=0a1c0e00 ecx=7c927304 edx=7c98c0d8 esi=0a1c0e00 edi=64043e74
eip=64019d9a esp=0022dd00 ebp=0022dd04 iopl=0         nv up ei pl nz na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00200202

Call stack:

But to be honest I do not understand what it means.
Any other suggestion?

0 Kudos
Message 29 of 43
steorn - Where did you get a "libnidaqmx.a" file?  I am trying to use the NIDAQmx driver in Linux with some real-time DAQ software (RTAI, not LabView) and in order to use the daqmx functions I have to link a static library when compiling.  The only library I have is a .so and I have been looking for a way to get a static version somehow.  If you have one is it possible to send it to me or tell me a way to generate one?
0 Kudos
Message 30 of 43