05-30-2013 04:18 AM
Hello,
I wish to use the IMAQdx and NI-Vision External Compiler Interfaces with Cygwin gcc/g++ compilers.
I am already doing this sort of game without any problem with the NI-VISA and NI-DAQmx External Interfaces (g++ appears to be happy with the dll files in C:\WINDOWS\system32 for NI-VISA, NI-488.2 and NI-DAQmx).
I have written a simple C test code that calls IMAQdx symbols.
I compile it from Cygwin terminal with the command :
gcc -I/cygdrive/c/PROGRA~1/NATION~1/Shared/EXTERN~1/C/include TestIMAQdx.c -L/cygdrive/c/WINDOWS/system32 -lniimaqdx -lnivision
It apparently compiles and links fine, but I get unreliable behavior and segmentation faults.
(But the camera is found and I get some informations from it, so the symbols are somehow found. But there seems to be some problems with memory alignments)
If I compile the very same C test code with MSVC from the Microsoft Visual Studio command line:
cl -IC:\PROGRA~1\NATION~1\Vision\Include -IC:\PROGRA~1\NATION~1\NI-IMA~1\include TestIMAQdx.c /link C:\PROGRA~1\NATION~1\Vision\Lib\MSVC\nivision.lib C:\PROGRA~1\NATION~1\NI-IMA~1\lib\msvc\niimaqdx.lib
Then, everything works fine. So, I guess it is not a bug in my C source file, but rather some incompatibilities between the library and the compiler. But since it is a C interface (and not, eg. a C++ interface, with ABI problems), I see no reason why it shouldn't work.
However, I cannot use MSVC for my application because I require linking with several Cygwin C++ libraries that are not compatible with MSVC (for ABI reasons). Since IMAQdx are C interfaces, it SHOULD work.
So:
Is there a compatible interface library available somewhere ? Could NI possibly provide a standard external interface ?
What could I possibly do to have g++ link properly ?
Why does it work like a charm with VISA and DAQmx, and not with IMAQdx and Vision ?
Thank you for your help.
05-31-2013 11:55 AM
Hi jsalort,
I have reproduced this issue with the code you provided. Specifically, I noted that some of the calls were corrupting the stack. This appears to be due to a mismatched calling convention. Looking at NIIMAQdx.h, it appears that the calling convention (stdcall for most functions) is NOT declared when __GNUC__ is defined (presumably under the assumption that GCC platforms were non-Windows and did not deal with multiple calling conventions).
I think you can work around this on your own by putting the following before including NIIMAQdx.h:
#define _NI_FUNC_DEFINED
#define NI_FUNC __stdcall
#define NI_FUNCC __cdecl
I have also filed this issue as CAR #410920 so that it can be addressed in the header file itself.
Eric
05-31-2013 12:55 PM
Sorry, missed one additional line you need:
#define _NI_FUNCC_DEFINED
06-03-2013 12:14 PM
Thank you. This was indeed the problem.
I also had to add:
#define IMAQ_STDCALL __stdcall
because I am also using calls from nivision.h
Best regards,