Thanks for your replies!
I've tried your suggestions and I also got some very usefull hints.
1) Jason's method seems to work fine, but I'm concerned, that this method might mess up the stack. As I understood __cdecl means, that the calling function removes the parameters from the stack after the function returned, while __stdcall means, that the function removes the parameters itself. gcs already pointed out that this calling convention is important.
2) gcs' suggestion of using attribute does not work (at least I wasn't able to find a difference, when using __attribute__((stdcall)) instead of __stdcall), but I had no experience with these compiler details so far.
3) a new approach to the problem: gcs also stated that "the NIDAQmx.lib library does have the symbols that are needed". This is surely true, but there seem to be different naming (or "decoration") conventions, as described at
Stdcall and DLL tools of MSVC and MinGWIn short: the internal represantations of function names have different "decorations". Especially gcc expects, that "@nn" (where nn is the size of all parameters in bytes) is appended to stdcall function names, while the MSVC dll uses the plain name without the "@nn".
Using Microsoft DLL's when Compiling Cygwin or Mingw describes a workaround. Basically one has to write a .def file and then create a library with the "right" names:
Setup:
------
I have copied all necessary files into the current directory:
NIDAQmx.h (from NI-DAQ\DAQmx ANSI C Dev\include)
NIDAQmx.lib (from NI-DAQ\DAQmx ANSI C Dev\lib\msvc)
nicaiu.dll (from C:\WINDOWS\system32)
together with one of the examples
Acq-IntClk.c (from NI-DAQ\Examples\DAQmx ANSI C\Analog In\Measure Voltage\Acq-Int Clk)
Procedure:
----------
1) call gcc to find the missing function names:
$ gcc Acq-IntClk.c -o Acq-IntClk.exe NIDAQmx.lib
gcc complains about undefined references as before.
2) put the names of the functions into a .def file (e.g. "mynicaiu.def"). The file should look like this (without -START- and --END-- lines, of course):
---------------START---------------
LIBRARY nicaiu.dll
EXPORTS
DAQmxCreateTask@8
DAQmxCreateAIVoltageChan@40
DAQmxCfgSampClkTiming@32
DAQmxStartTask@4
DAQmxReadAnalogF64@36
DAQmxGetExtendedErrorInfo@8
DAQmxStopTask@4
DAQmxClearTask@4
----------------END----------------
3) build a library (e.g. "libmynicaiu.a") from nicaiu.dll and mynicaiu.def:
$ dlltool --input-def mynicaiu.def --dllname nicaiu.dll --output-lib libmynicaiu.a -k
4) use libmynicaiu.a instead of NIDAQmx.lib for compilation with gcc:
$ gcc Acq-IntClk.c -o Acq-IntClk.exe libmynicaiu.a
This will finally create Acq-IntClk.exe, which seems to work! But I haven't done extensive tests yet and I am really not a compiler/linker expert.
The advantage of this method is, that there is no need to change the calling conventions in "NIDAQmx.h".
The disadvantage is, that one has to find out the right function names, which must be added to mynicaiu.def. The problem here is the right number nn in the appended "@nn".
The easiest solution would surely be a library, which is built by National Instruments. Perhaps it is really just a matter of the "right" linker option? A KnowledgeBase article solving this problem and supplying such a library would be great!
Sincerely,
Jens