Thread: Os Detection
View Single Post
Old Nov 17th, 2004, 12:22 PM   #17
alunw
Newbie
 
Join Date: Nov 2004
Posts: 3
Rep Power: 0 alunw is on a distinguished road
You have to compile your program separately for each platform, so you can just invent your own define and test it

e.g. compiling on Windows cl -DWIN32 fred.cpp

compiling on Linux gcc -Dlinux fred.cpp

etc.

On Unix/Linux make usually uses a variable called CFLAGS or CPPFLAGS and CC when doing compiles so you can sometimes have a makefile that works on multiple platforms
but still detects the OS - something like.

$(CC) $(CFLAGS) fred.cpp

I build my programs to run on everything from Windows CE and MS-DOS through to Windows and AIX, and find this technique works well.
alunw is offline   Reply With Quote