1

Is there a way to get the build to see an environment variable so that all the files can be built differently with one Environment variable change. Such as

#ifdef UseFirstDir
    #include <C:\MyFirstDir\ImportantIncludes.h>
#else
    #include <C:\MySecondDir\ImportantIncludes.h>
#endif

1 Answer 1

0

Not environment, no.

If you have access to the compilation command line you can do the equivalent of #define from there:

avr-gcc ... blah blah ... -DUseFirstDir

That is most effective if you are using a Makefile build system rather than relying on the Arduino IDE which doesn't give you access to those kind of things without modifying the core configuration, which isn't nice, and certainly is neither permanent nor flexible (doesn't survive upgrades to new versions, and isn't easy to turn on and off at will).

A better IDE, though, can do it. Facilities for setting control flags like that exist within UECIDE and it's possible to tie them to menu entries to make switching options on and off easier. It's not documented how to do it though (yet).

Or you can just have a list of #define options at the top of your sketch:

/* Uncomment this to use the first directory. */
// #define UseFirstDir

// .... later ....

#ifdef UseFirstDir
    #include <C:\MyFirstDir\ImportantIncludes.h>
#else
    #include <C:\MySecondDir\ImportantIncludes.h>
#endif
2
  • I have Cygwin, but the command line (bash or dos) is not finding avr-gcc. The second option seems best for now. Commented Dec 21, 2016 at 15:56
  • @Gregg I have just blogged about adding menu entries for a sketch in UECIDE.. Commented Dec 21, 2016 at 16:24

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.