where is #define __linux__
I'm doing some code which is intended to work on linux and sunos. I was poking through the header files in /usr/include on my debian box and found a line in g++-3/stl_config.h which specified: #if defined(__linux__) after a quick test, I found out this is true on linux, and not true on solaris when using gcc. However, grep -r '__linux__' * doesn't reveal the location where it is in fact #defined. Anyone have a clue what's going on? While on the topic, is there a magic preprocessor definition that lets me know if I'm on sunos/solaris?
Re: where is #define __linux__
On Mon, Jan 08, 2001 at 11:05:54PM -0800, Aaron Brashears wrote: | I'm doing some code which is intended to work on linux and sunos. I | was poking through the header files in /usr/include on my debian box | and found a line in g++-3/stl_config.h which specified: | | #if defined(__linux__) | | after a quick test, I found out this is true on linux, and not true on | solaris when using gcc. However, grep -r '__linux__' * doesn't reveal | the location where it is in fact #defined. | Not sure, but it could be defined in the compiler itself. | Anyone have a clue what's going on? While on the topic, is there a | magic preprocessor definition that lets me know if I'm on | sunos/solaris? | I know that __GNUC__ and __GNUG__ are defined if using gcc/g++ respectively, but I don't know of a Solaris specific label. Maybe grepping through the g++ sources for __.*__ would help? -D
Re: where is #define __linux__
On Mon, Jan 08, 2001 at 11:05:54PM -0800, Aaron Brashears wrote: While on the topic, is there a magic preprocessor definition that lets me know if I'm on sunos/solaris? yes indeedy. multiple. there is __sun__ to detect solarisORsunos, and __svr4__ to detect solaris specifically, I believe. there is also __sparc__ and __i386__ to deal with
Re: where is #define __linux__
On Mon, Jan 08, 2001 at 11:05:54PM -0800, Aaron Brashears wrote: I'm doing some code which is intended to work on linux and sunos. I was poking through the header files in /usr/include on my debian box and found a line in g++-3/stl_config.h which specified: #if defined(__linux__) after a quick test, I found out this is true on linux, and not true on solaris when using gcc. However, grep -r '__linux__' * doesn't reveal the location where it is in fact #defined. This is defined in the gcc specs file, see /usr/lib/gcc-lib/i386-linux/${version}/specs Anyone have a clue what's going on? While on the topic, is there a magic preprocessor definition that lets me know if I'm on sunos/solaris? Just as a side note, think twice (or even thrice) before using that symbols. Is the code really linux specific? For example, a Linux kernel feature certainly is, but many other things aren't. Often it is more appropriate to check for specific POSIX features, or the existance of the GNU C library, or something else entirely. autoconf can help here, as well as liberty (libiberty :) Of course, this depends on the thing you want to implement, but choosing the right check makes the software more portable. To see a full list of compiler defined symbols, use gcc -dM -E - /dev/null Thanks, Marcus
Re: where is #define __linux__
D-Man wrote: On Mon, Jan 08, 2001 at 11:05:54PM -0800, Aaron Brashears wrote: | I'm doing some code which is intended to work on linux and sunos. I | was poking through the header files in /usr/include on my debian box | and found a line in g++-3/stl_config.h which specified: | | #if defined(__linux__) | | after a quick test, I found out this is true on linux, and not true on | solaris when using gcc. However, grep -r '__linux__' * doesn't reveal | the location where it is in fact #defined. | Not sure, but it could be defined in the compiler itself. | Anyone have a clue what's going on? While on the topic, is there a | magic preprocessor definition that lets me know if I'm on | sunos/solaris? This may help (on a linux i386 machine): kleptog/~touch /tmp/x.c kleptog/~gcc -E -dM -c /tmp/x.c #define __linux__ 1 #define linux 1 #define __i386__ 1 #define __i386 1 #define __GNUC_MINOR__ 95 #define i386 1 #define __unix 1 #define __unix__ 1 #define __GNUC__ 2 #define __linux 1 #define __ELF__ 1 #define unix 1 -- Martijn van Oosterhout [EMAIL PROTECTED] http://cupid.suninternet.com/~kleptog/
Re: where is #define __linux__
On Tue, Jan 09, 2001 at 02:22:45PM +0100, Marcus Brinkmann wrote: Just as a side note, think twice (or even thrice) before using that symbols. Is the code really linux specific? For example, a Linux kernel feature certainly is, but many other things aren't. Often it is more appropriate to check for specific POSIX features, or the existance of the GNU C library, or something else entirely. autoconf can help here, as well as liberty (libiberty :) Of course, this depends on the thing you want to implement, but choosing the right check makes the software more portable. Yes, the code is linux and solaris specific. In linux, I'm testing /proc, and in solaris, I'm placing a syscall(). As a different but related side note, AFAIK POSIX doesn't specify a way to tell if a particular file is open. I'm coding up a simplified fuser function to help boost system performance on our servers. To see a full list of compiler defined symbols, use gcc -dM -E - /dev/null Woohoo, that's pretty cool. Thanks for the info.