Kevin said:
We are working on a project for school (university). We work on a server
that
runs Solaris, but some of us also work on our project at home using their
Linux.
For now I have solved this problem with a (ugly) temporary solution:
QString OS::getOperatingSystem() {
return "Solaris 8";
}
But under Linux this, of course, gives the wrong result.
As you can see (from the use of QString), we use Qt. Maybe Qt has a way to
get
the name and version of the OS. But I can not find anything yet.
We compile on the same platform we run the program, so this IS a possible
solution. But if possible I would like a more elegant solution than using
macro's.
Kevin
More elegant solution????
Commercial code like Qt uses a lot of macros for system dependent things.
They handle compatibility with autoconf automake, which generates the
appropriate macro definitions and makefiles for compiling in your system.
#ifdef linux
or #ifdef Linux
should just work, specially when all you have to comply is with Linux
and Solaris compatibility.
another thing you can try is using make rules.
Have your makefile include a golbal rules file
localrules.$(OSNAME)
eg
localrules.Linux
localrules.Solaris
You can use 'uname' to use the rules that apply to the system you are
compiling on, and maybe define compile time variables -DLIN_COMP_VAR.
Again, this is one of the things macros are good for. Don't be afraid
to use them....
Jorge L.