LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

clang, CVI, C99

Solved!
Go to solution

Hello all,

 

no question, just a hint to avoid a pitfall I ran into...

 

If you are using C99 features, be aware that the definitions such as INFINITY or NAN will not be available for an external compiler such as clang.

 

This is because these definitions (in math.h) are preceded by

 

#if _CVI_C99_EXTENSIONS_

 

For an external compiler this condition is FALSE; hence switching to an external compiler one will get errors due to undeclared identifiers.

 

This of course can be avoided by adding

 

#ifndef NAN
#define NAN             0xCp125f
...

#endif

 

to an include file.

 

A nicer solution would be a modified if clause in the math.h file, or defining _CVI_C99_EXTENSIONS_ for external compilers, but this would be left to NI...

0 Kudos
Message 1 of 4
(3,421 Views)

Hi Wolfgang,

 

A better solution would be to modify your clang interface in order to define _CVI_C99_EXTENSIONS_ when C99 is enabled.

 

You do this by adding /D_CVI_C99_EXTENSIONS_ to the C99 Flags field in the Options>>Build Options>>Build Process Options>>...>>Edit>>Advanced dialog box.

 

Because CVI can't assume that a given 3rd party compiler supports C99, it can't always define that macro when using a 3rd party compiler. But it uses the C99 flags field in the compiler interface specification to define an option that it can use for a given compiler, when C99 is enabled for the project configuration. If that field isn't blank, it means that the compiler supports C99, which means that it's also okay to define that macro.

 

The clang template should have included the /D_CVI_C99_EXTENSIONS_ definition. Sorry about that.

 

Luis

 

 

Message 2 of 4
(3,401 Views)
Solution
Accepted by Wolfgang

Dear Luis,

 

a better solution is always welcome Smiley Wink

 

I have tried your suggestion but somehow it didn't work:

 

what I did: in the field C99 Flags I have added your text, so now the field reads --std=c99 /D_CVI_C99_EXTENSIONS_

 

however, compilation yields an error:  error reading '/D_CVI_C99_EXTENSIONS_'

 

after investigating the issue the correct and hence even better solution seems to be to modify the field as follows:

 

C99 Flags: --std=c99 -D _CVI_C99_EXTENSIONS_

 

(that is, you have missed a space after the D and confused the slash with the minus)

 

This way I can omit my extra header and compilation seems to succeed.

 

As you have already mentioned, it would be nice if the ecc files could be updated accordingly

0 Kudos
Message 3 of 4
(3,384 Views)

You're right, I was using CVI's /D syntax, but I should have been using the -D clang syntax. However, it shouldn't have required whitespace between -D and the variable. That part is odd. But I guess it's not all that important, in any case.

 

Luis

0 Kudos
Message 4 of 4
(3,360 Views)