Re: Compiling code on different machine?
 
On Mar 6, 1:30 pm, Jeff Schwab <j...@schwabcenter.com> wrote:
mlt wrote:
Is there someway in C++ to read a machines ID of somekind?
I have some code that should be compiled in a certain way
when it is compiled on a laptop and in another way when its
compiled on a desktop.
Currently I do:
#define DESKTOP 1
in main() {
    if(DESKTOP)
    {
        // do desktop compilation
    }
    else
    {
        // do laptop compilation
    }
}
I could be nice if there was some system variable that I
could test for that would identify the correct machine.
There's no portable mechanism (AFAIK) guaranteed by the C or
C++ standards, but try gethostbyname(3).
He spoke of compiling, not run time.  My makefiles regularly do
this, using $(shell uname -n) to get the host name.  This still
doesn't give me any information about the type, however;
basically, I need a different configuration file for every host
I support.  On Unix, this is easily handled by means of symbolic
links, but under Windows, I don't know.  (And of course, this
supposes standardizing on a common make for all platforms.  The
expression I gave above is for GNU make; other makes will likely
have a different syntax, if they support it at all.)
--
James Kanze (GABI Software)             email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
                   Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34