Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

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

Thanks to all of you in this thread.  Without official gcc support from NI, these postings have proven to be an invaluable resource.

I had to do things a bit differently, so here's the details:

1) copy nidaqmxbase.dll to a working directory, in my case:
C:\Program Files\National Instruments\NI-DAQ\DAQmx ANSI C Dev\lib\gcc

2) Execute pexports to generate .def file:

http://www.emmestech.com/moron_guides/moron1.html has useful info on using microsoft dlls with cygwin/mingw

/cygdrive/c/Program\ Files/pexports-0.43/bin/pexports.exe nidaqmxbase.dll | sed 's/^_//' > nidaqmxbase.def

3) Use dlltool to create libdaqmxbase.a

dlltool --input-def nidaqmxbase.def --dllname nidaqmxbase.dll --output-lib libnidaqmxbase.a -k

4) Link and build with the appropriate directories -I and -L in your Makefile, or copy the .a to a directory in your path

- I/cygdrive/c/"Program Files"/"National Instruments"/"NI-DAQmx Base"/Include
-L"/cygdrive/c/Program Files/National Instruments/NI-DAQ/DAQmx ANSI C Dev/lib/gcc"

(hmm, just noticed I'm including the header from Base, and put my .a in NI-DAQ, might edit this post later if I clean things up)

5) I had to switch the driver in the System->Hardware->Device Manager to NI-VISA USB Devices->NI USB-6501 24-line Digital IO
I was getting DAQmxBase Error -200220: <err>Device identifier is invalid.  Then I found the following link.  After this, things seem to be working fairly swimmingly.

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

Though I still get warnings about uInt32 and int32 -- I think a couple of typedefs should take care of it.

Please let me know if you find some glaring error, or have a better solution.

0 Kudos
Message 31 of 43
(6,380 Views)
I am trying to use the file provided by Joe Savage (post 9: NIDAQmx.C) with Dev-C++ under Windows XP, but I am still getting the same error ([Linker error] undefined reference to `DAQmxCreateTask@8').
I assume I should have '-NIDAQmx.c' in my compiler options and the file in one of the include paths. Can anyone tell me where I am going wrong?
0 Kudos
Message 32 of 43
(6,301 Views)
Never mind: I'm an idiot. It works fine with the library produced from the modified .defs file. I just wasn't including the library in the compiler options.
0 Kudos
Message 33 of 43
(6,264 Views)

Many thanks to everyone who posted to this thread. I'd never gone through the process of creating an object library before and having followed the instructions in the post by dplamp (message 14) I was suprised how smoothly it went.

 

One thing I could add is that the bash script he gives doesn't work for me. Bash gave far too vague error messages to allow me to figure it out. I just prepared the def file by hand and it took maybe two minutes. I actually used excel to trim the whitespace and remove the excess underscores (trim,mid and len functions), less time than it takes to download and install the utilities. Thanks for the clear commenting in your script dplamp !

 

Great to be using a lean, clean, effficient development environment rather than the expensive monstrosity which is Labview.

Message Edited by david_TKK on 02-24-2009 08:41 AM
0 Kudos
Message 34 of 43
(5,929 Views)

I'd like to thank everybody on this board, this has helped me immensely.

0 Kudos
Message 35 of 43
(5,121 Views)

I have been trying to get this to work for the last 2 days but cannot.  Maybe someone can help me.  Let me explain my setup first;

 

windows 7 64bit

nidaqmx 9.1.7

mingw 64 bit

 

I can create the def file (from C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc\nidaqmx.lib) wich i have attached.  Although it does not have the @ symbols in it.  Is it correct?

 

I then ran dlltool and created the libnidaq.a file which i used in my linker.

 

Everything works up to there.  The problem is when i try to build i get the following error:

 

c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.0/../../../../x86_64-w64-mingw32/bin/ld.exe: i386 architecture of input file `../../Createdef/libnidaq.a(dyyrh.o)' is incompatible with i386:x86-64 output
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.0/../../../../x86_64-w64-mingw32/bin/ld.exe: i386 architecture of input file `../../Createdef/libnidaq.a(dyyrt.o)' is incompatible with i386:x86-64 output
collect2.exe: error: ld returned 1 exit status
make[2]: *** [dist/Debug/MinGW-Windows/libHelloWorldC.dll] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

 

I am pretty sure everything is 64 bit so i don't know where this error is coming from.

 

Any help would be greatly appreciated.

0 Kudos
Message 36 of 43
(4,936 Views)