Re: Preprocessor macros debugging

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Dec 01, 2006 at 14:03:33 -0600, John Love-Jensen wrote:
> Hi Peter,
> 
> > Is there any tool, switches to cpp or a relatively simple way to alter
> > cpp sources so I can get a dump of #defined macros?
> 
> I use this trick:
> 
> You can generate a list of the built in defines by doing this:
> 
> echo '' | gcc -E -dM -x c - | sort
> 
> echo ''   -- for our mock empty source file
> gcc       -- our favorite toolchain driver (or g++)
> -E        -- preprocess only
> -dM       -- display defines
> -x c      -- treat as C (or -x C++)
> -         -- use stdin as the source file
> sort      -- put the defines in more human readable order
> 
> You can use that trick with particular #include files to see what the
> vestigial #defines are (vestigial because it won't list #undef'd
> identifiers).
> 
> You can do the same thing for, say, Foo.c by doing this:
> 
> gcc -E -dM -x c Foo.c | sort
> 
> Using some shell magic, you can eliminate the "empty source" pre-defines
> from the remainder of what's introduced (and not #undef'd) in Foo.c.
> 
> If you are using C++, use g++ and -x c++.

Thanks, it helped me a lot. It turned out that, in one of the libraries,
somebody unconditionally defined __SUNPRO_CC, which tricked boost into
using Borland- and SUNPro-specific macro tricks, even when compiling
with gcc.

Cheers,
Peter

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux