Re: Conditional compilation
On 12/26/2012 9:00 AM, Giuliano Bertoletti wrote:
> this is a rather platform specific issue that might however have a
> general solution (I hope).
> I need to perform a conditional compilation of a C++ source code
> depending on which host I'm compiling it on.
> for example:
> #if <compiling on host1>
> #import <pathA/file>
> #elseif <compiling on host2>
> #import <pathB/file>
> ... // error! unknown host
> As you can easily see the "#import" directive inside each block is
> MSVC++ specific, however I cannot avoid using it and most importantly I
> need conditional compilation because "pathA" and "pathB" differs
> depending on extenal factors like the OS type (32 or 64bit) or more
> generally on the host.
IOW, moving the compilation from one host to another should change the
behavior of your code (by means of conditional compilation). That's
against the fundamental concept that the code (or the behavior of the
resulting program) should not differ based on the environment, if only
the standard means are used. It can differ if the supplied environment
is different, of course, like compiler switches, etc.
> What I'm wondering is if there's some way to set an extern environment
> variabile and have the compiler read it and use when deciding which
> portion to compile.
There probably is. Most likely you should be able to define some kind
of preprocessor macro by means of a compiler switch similar to "/D
MACRONAME=MACROVALUE", and make sure your hosts supply different
'MACROVALUE' string based on their environments, for instance. But the
details of that are outside of the Standard language concern, they are
OS- and platform- and tool-specific. RTFM for your compiler.
> The idea is indeed to have a set of hosts on which it compiles without
> modifying the source code (clearly new hosts would need to be added)
> The usual way if it were an external library would be to set the path
> for .h and .lib into the IDE or Makefile, however this is not the case.
I do not respond to top-posted replies, please don't ask
|All times are GMT. The time now is 11:41 PM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.