LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Communicating with the Preprocessor

Solved!
Go to solution

CVI 2017, Windows

 

Is there a way to send something to the preprocessor from the outside world upon application build? 

 

I am using some of the same source code files for two applications which use the same hardware.  The two applications have different .uir, and thus different .h files for the UIRs.  I need to tell the preprocessor to use either UIR1.h or UIR2.h  for the build, based on something.

 

Before I dump a lot of detail here regarding multiple .h files, and communicating between these files, does anyone have an idea to solve the above.

0 Kudos
Message 1 of 5
(2,680 Views)

The classical way to do this is to make a define in your project build and in your source code use conditional compile similar to this:

#if defined(USE_UIR1)
#include "uir1.h"
#elif defined(USE_UIR2)
#include "uir2.h"
#endif
Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 5
(2,611 Views)

The problem is defining USE_UIR1.  Since the pre-processor works on things before variables are defined, there needs to be some other mechanism to define USE_UIR1 and USE_UIR2, in order to do the conditional compile.

 

I have tried to define something in the top .c file, prior to the first .h file include, and that does not seem to work. 

 

So you say, "make a define in your project build ".  Where would you do this?

0 Kudos
Message 3 of 5
(2,594 Views)
Solution
Accepted by topic author hendra@ngms

I only have an older CVI version installed so the actual location of these settings may have changed but in my version when I open a project I can go in the menu to Build->Configuration->Manage Configurations

In there select the Configuration for your build and then press Edit. Select the Build Options... and in there under the section Compiler Defines you can add additional defines that will be passed to the C compiler for every source file when it is processed. For the define in question you would add a /DUSE_UIR1 to the list of defines that might be already there, seperated by a space from other defines. /D is the prefix that tells the preprocessor stage in the compiler that everything that follows until the next space should be treated as a predefined #define.

Rolf Kalbermatter
My Blog
Message 4 of 5
(2,585 Views)

Rolf,

You nailed it.  Works exactly the same in 2017.  Figured there must be a way for the outside world to tell the preprocessor something, but had not encountered this before. 

 

Thanks very much... Gary

0 Kudos
Message 5 of 5
(2,565 Views)