How do you do '#ifdef Solaris'?

How do you do '#ifdef Solaris'?

Post by Robert De Wol » Wed, 13 Dec 1995 04:00:00



Does anyone know of an ifdef which can be used to determine if
a program is being compiled for Solaris?

Thanks

 
 
 

How do you do '#ifdef Solaris'?

Post by Phil Edwar » Thu, 14 Dec 1995 04:00:00




+ Does anyone know of an ifdef which can be used to determine if
+ a program is being compiled for Solaris?

Well, I don't use Solaris myself, but take a look at the first
part of the output from a quick "gcc -v":

    /usr/local/lib/gnu/lib/gcc-lib/alpha-dec-osf3.0/2.7.1/cpp
   -lang-c -v -undef -D__GNUC__=2 -D__GNUC_MINOR__=7 -Dunix
   -D__osf__ -D__alpha -D__alpha__ -D_LONGLONG -DSYSTYPE_BSD
   -D_SYSTYPE_BSD -D__unix__ -D__osf__ -D__alpha -D__alpha__
   -D_LONGLONG -D__SYSTYPE_BSD__ -D_SYSTYPE_BSD -D__unix
   -D__SYSTYPE_BSD -Asystem(unix) -Asystem(xpg4) -Acpu(alpha)
   -Amachine(alpha) -D__LANGUAGE_C__ -D__LANGUAGE_C -DLANGUAGE_C
   foo.c /tmp/ccaapiEa.i

If you have the GNU compiler, take a look at the symbols it
predefines.  The command line I used to produce the above just
now was "gcc -v foo.c -o foo" -- no special -D(efines) or
anything -- and I can right away test for the hardware, the OS,
even that fact that it's a *nix and not some PC or a VMS
platform.

Luck++;
Phil

--
#include<std/disclaimer.h>               The gods do not protect fools. Fools



 
 
 

How do you do '#ifdef Solaris'?

Post by Andrew Dunsta » Sat, 16 Dec 1995 04:00:00





> + Does anyone know of an ifdef which can be used to determine if
> + a program is being compiled for Solaris?

> Well, I don't use Solaris myself, but take a look at the first
> part of the output from a quick "gcc -v":

>     /usr/local/lib/gnu/lib/gcc-lib/alpha-dec-osf3.0/2.7.1/cpp
>    -lang-c -v -undef -D__GNUC__=2 -D__GNUC_MINOR__=7 -Dunix
>    -D__osf__ -D__alpha -D__alpha__ -D_LONGLONG -DSYSTYPE_BSD
>    -D_SYSTYPE_BSD -D__unix__ -D__osf__ -D__alpha -D__alpha__
>    -D_LONGLONG -D__SYSTYPE_BSD__ -D_SYSTYPE_BSD -D__unix
>    -D__SYSTYPE_BSD -Asystem(unix) -Asystem(xpg4) -Acpu(alpha)
>    -Amachine(alpha) -D__LANGUAGE_C__ -D__LANGUAGE_C -DLANGUAGE_C
>    foo.c /tmp/ccaapiEa.i

> If you have the GNU compiler, take a look at the symbols it
> predefines.  The command line I used to produce the above just
> now was "gcc -v foo.c -o foo" -- no special -D(efines) or
> anything -- and I can right away test for the hardware, the OS,
> even that fact that it's a *nix and not some PC or a VMS
> platform.

try this instead, to see the automatic DEFINEs:

touch does-not-exit.c; gcc -E -dM does-not-exist.c ; rm does-not-exist.c

On my Solaris machine this produces the following:

#define __GCC_NEW_VARARGS__ 1
#define __sparc 1
#define __svr4__ 1
#define __GNUC_MINOR__ 6
#define __sun 1
#define sparc 1
#define __sun__ 1
#define __unix 1
#define __unix__ 1
#define sun 1
#define __GNUC__ 2
#define __sparc__ 1
#define unix 1

cheers

andrew

----------------------------------------------------------
       Christmas has been cancelled -- Joseph has confessed all.
-------------------------------------------------------------------------

 
 
 

How do you do '#ifdef Solaris'?

Post by Robert De Wol » Sat, 16 Dec 1995 04:00:00




>   -D_SYSTYPE_BSD -D__unix__ -D__osf__ -D__alpha -D__alpha__

 Much thanks for all the info about gcc.

Now I need the answer to a (perhaps) much tougher question:
How can it be done using the Solaris compiler (Sparkworks)?

 
 
 

How do you do '#ifdef Solaris'?

Post by thefu » Sun, 17 Dec 1995 04:00:00



: Does anyone know of an ifdef which can be used to determine if
: a program is being compiled for Solaris?

Use GNU autoconf and #defines based on actual feature tests
rather than operating system vendor versions.
This is much easier in the long run.  You'll look like a
cool programmer too.

Bob

 
 
 

How do you do '#ifdef Solaris'?

Post by Dieter Dey » Sun, 17 Dec 1995 04:00:00




: >   -D_SYSTYPE_BSD -D__unix__ -D__osf__ -D__alpha -D__alpha__

:  Much thanks for all the info about gcc.

: Now I need the answer to a (perhaps) much tougher question:
: How can it be done using the Solaris compiler (Sparkworks)?

#include <sys/sockio.h>

#if defined _SC_STREAM_MAX
#define sun5
#else
#define sun4
#endif

--


 
 
 

How do you do '#ifdef Solaris'?

Post by Helium3 grou » Sun, 17 Dec 1995 04:00:00


The manpage for the preprocessor (cpp) should tell you about the predefined
symbols for your computer.
(On hpux the relevant symbols are listed in the section on the -U option.)

Fergus Clancy.

 
 
 

How do you do '#ifdef Solaris'?

Post by Casper H.S. Dik - Network Security Engine » Tue, 19 Dec 1995 04:00:00



Quote:>Does anyone know of an ifdef which can be used to determine if
>a program is being compiled for Solaris?

In general, #ifdef'ing for a partcular OS is wrong.
You should #ifdef for features.o

(E.g., if you ifdef' for Solaris 2.x you can't make the distinction
between 2.4 not having bcopy in libc.so and 2.5 having bcopy in
libc.so.)

But both gcc (2.7.0+) and Sun's C compiler (3.0+) now support -D__SVR4.

Casper

 
 
 

How do you do '#ifdef Solaris'?

Post by Howard B. Owe » Fri, 29 Dec 1995 04:00:00



Quote:>Does anyone know of an ifdef which can be used to determine if
>a program is being compiled for Solaris?


Quote:>But both gcc (2.7.0+) and Sun's C compiler (3.0+) now support -D__SVR4.

  Oh good! Here's what I had to do to cover SunPro cc and gcc prior to
2.7.0:

        #ifdef(sun)
          #if defined (__SVR4) || defined (__svr4__)
            #define SOLARIS
          #endif
        #endif

--

Internet Guy/Webmaster      1001 Murphy Ranch Rd.            37 A0 46 EE BE
408-324-6576 Voice and FAX  Milpitas CA 95035-7912           95 DB 92 E8 39
I am not a pay TV service!  http://www.egbok.com/hbo.html    80 89 A9 F9 3D
FB

 
 
 

How do you do '#ifdef Solaris'?

Post by Jason C. Aust » Sat, 30 Dec 1995 04:00:00


=> Does anyone know of an ifdef which can be used to determine if
=> a program is being compiled for Solaris?

        Unfortunely, there's no single pre-defined symbol to recognize
Solaris over SunOS, but you can do it with two symbols:

To identify Solaris:

#if defined(sun) && defined(__SVR4)

To identify SunOS:

#if defined(sun) && !defined(__SVR4)

        Both Sun's cc and GNU gcc define these symbols.
--
Jason C. Austin

Web:   http://gis-www.larc.nasa.gov/~jason

 
 
 

1. starting off a dos-smtp-''project''

greetings!

I have a certain amount of C/c++/asm etc etc - no big deal...
not anywhere near expert but am willing to tackle this idea.

a c program running in dos that will smtp a text file
from one machine on a network to another smtp server.

the file i/o etc isnt the problem , its where to start
on the smtp networking part that i'd like some words of
guidance on.
of course - as usual , someone has already written this
program and if i can get the person who has done this
and scrounge a copy of him/her ??.....

regards all
A Learner
(aka paul kearney)

2. Linux Newbie Day 1

3. Is e2label 'dangerous' when done on a 'live' file system?

4. Kernel panic: No init found ?

5. dos won't recognize my extended dos partition

6. Using RCS in makefile

7. Newbie: What's done by 'alog' ?

8. ipx_interface: requested device (eth0) is down ?!?!

9. hung after 'exit()' is called...what's it doing?

10. HELP: Connectivity between DOS/DOS and DOS/Linux

11. Doing 'stty erase ^H' on remote shells

12. How do I get 'w' to say that i am doing something else

13. Cannot mount dos 'd' drive