Re: Conditional compilation

Discussion in 'C++' started by Victor Bazarov, Dec 26, 2012.

  1. 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>
    > #else
    > ... // error! unknown host
    > #endif
    >
    > 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.


    V
    --
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Dec 26, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris P
    Replies:
    0
    Views:
    424
    Chris P
    Oct 28, 2003
  2. avishay

    Conditional compilation in VHDL

    avishay, Aug 1, 2005, in forum: VHDL
    Replies:
    4
    Views:
    2,976
    Andy Peters
    Aug 1, 2005
  3. Praveen
    Replies:
    0
    Views:
    341
    Praveen
    Apr 12, 2005
  4. Praveen Ramesh
    Replies:
    2
    Views:
    2,141
    Steven Cheng[MSFT]
    Apr 13, 2005
  5. Alec S.
    Replies:
    10
    Views:
    10,057
    Alec S.
    Apr 16, 2005
Loading...

Share This Page