Hi
I am trying to write something that compiles and runs
correctly on both Linux and Windows. I am running bash
in Ubuntu on Linux, and I try to set environment variables
in the makefile just before the compile lines. I then write
something in the code like

int main()
{
#ifdef UBUNTU
   std::cout << "Ubuntu = true\n";
#else 
   std::cout << "Ubuntu = false\n";
#endif
   return 0;
}

No matter what variant of this I try (#if vs. #ifdef, UBUNTU vs $UBUNTU,
setting the environment variable on the command line before the make
command, etc. I always get "Ubuntu = false". Can someone set me straight
on how to get this working?

Dave

Are you setting an environment variable, or creating a symbol definition? Those are two completely separate things. Can you show an example of the make file?

Edited 5 Years Ago by Narue: n/a

@Narue --

Thank you for replying. Here's my make file line:

Tester_dbg.o : Tester.cpp
        UBUNTU=true
        $(GPP) -g -c -o Tester_dbg.o Tester.cpp

tester_dbg : Tester_dbg.o
        $(GPP) -o 3mtest_dbg Tester_dbg.o

I also tried setting the variable on the command line:

david@Thinkpad:~/finance/3m$ UBUNTU=true
david@Thinkpad:~/finance/3m$ echo $UBUNTU
true

Anything you can tell me would be greatly appreciated.

You're not doing what you think you're doing, which is set a preprocessor symbol during compilation. Try using a compiler switch instead:

$(GPP) -D UBUNTU -g -c -o Tester_dbg.o Tester.cpp
This question has already been answered. Start a new discussion instead.