Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Can't compile the example code.

Dear all,

  Recently, I need to use C to do some measurement with our board NI 5734. I've read the NI-DAQmx C reference help and tried to run some example code about voltage acquisition. But I can not compile these example codes. The following pictures show the error and my gcc version. The last picture is my code screenshot. I've searched many solutions but they all didn't work. Can anybody help me? Thank you very much!

NothingForever3_1-1652957175865.png

NothingForever3_0-1652957048435.png

NothingForever3_2-1652957344904.png

 

 

0 Kudos
Message 1 of 2
(1,604 Views)

The NIDQAmx for Windows install pretty much expects MS Visual C++ to be used for the C/C++ examples. Using gcc to compile source code under Windows is always an "interesting" exercise but only if you are familiar with gcc in general and its Windows specific issues. Traditionally gcc was very bad in compiling Windows tailored source code. That has improved a lot in the last 10 years but compiling is only the second step after the precompiler pass and before the linker step. And in terms of linking, each compiler still has its own specific conventions and preferences. This is not different here.

 

First when trying to cross compile you always have to be weary of those pesky #pragma statements. They are by definition a compiler specific extension and while there are some that have gained widespread adoption (for instance the #pragma pack() statement) most should be considered compiler specific unless you have explicitly tested them to work for your compiler too.

 

The statement here that necks you in part is the #pragma comment(lib, <some library>) one. This is a Microsoft C specific extension. gcc won't complain about it since a compiler is supposed to try to interpret #pragam statements and if it doesn't know them to simply ignore them. The gcc way of specifying link libraries is to add their name to the command line -l<library name> (this is a lowercase L in case you wonder).

 

The second problem is that your gcc compiler has no idea where it could find that library. You need to pass a command line parameter to it such as -L"<path to directory where it should look for libraries)"

 

The third problem likely will be that gcc wants the link libraries in the ar (object archive) *.a file format. This is similar to a Microsoft COFF formatted *.lib file but not quite the same. In the past you absolutely had to use Windows specific gcc variants such as MinGW to be able to use Microsoft *.lib files. Stock gcc simply did not know about the COFF library format. I believe the gcc folks have deviated a bit from that strict refusal to deal with anything that sounds and smells like Microsoft, but am not having high hopes that it is even today a seamless operation. NIDAQmx for Windows does not come with ar format libraries as far as I know, so if you absolutely want to use your stock gcc install you have to resort to extracting the individual object files from the lib file using the Microsoft lib tool or something compatible, then repacking it into the ar format with the gcc ar tool. Second less painful solution would be to use the MingW compiler toolchain instead. This is a gcc variant that is specifically adapted to deal with Microsoftismes in C compiling and linking.

 

Note: I see that you already use MingW, so the third problem should be not an issue in your case. But problem 1 and 2 still apply.

 

The most pragmatic (what a nice word to avoid to have to use lazy) solution would however be to install the Community edition of Visual Studio or Visual Code.

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 2
(1,562 Views)