Danilo's Tech Blog

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Wednesday, 9 January 2013

How to inspect expanded C macros with gcc/gcc+

Posted on 12:04 by Unknown
Sometimes you get compilation errors in gcc/g++ and you'd like to inspect the output from the C compiler pre-processor to figure out why certain macros were expanded in such as way to cause an error.
The solution is simply to remove the -o and -c options from your gcc/g++ command line and replace it with

gcc/g++ -E -dD

this will generate on your terminal only the C pre-processor output that is eventually fed to the C/C++ compiler.

For example you are trying to compile Mozilla SpiderMonkey 1.7 and one of  the compiler lines is the following:

/usr/bin/gcc  -Djs_1_7_EXPORTS -DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DHAVE_LOCALTIME_R -DX86_LINUX -D_IEEE_LIBM -DJS_EDITLINE -DEDITLINE -DHAVE_VA_COPY -DVA_COPY=va_copy -DPIC -DANSI_ARROWS -DHAVE_TCGETATTR -DHIDE -DUSE_DIRENT -DSYS_UNIX -DHAVE_STDLIB -DUNIQUE_HISTORY -O3 -DNDEBUG -fPIC -I../js-1.7  -fPIC -o CMakeFiles/js-1.7.dir/jsarena.c.o   -c js-1.7/jsarena.c

To see the expanded C macros run the following command:

 /usr/bin/gcc  -E -dD -Djs_1_7_EXPORTS -DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DHAVE_LOCALTIME_R -DX86_LINUX -D_IEEE_LIBM -DJS_EDITLINE -DEDITLINE -DHAVE_VA_COPY -DVA_COPY=va_copy -DPIC -DANSI_ARROWS -DHAVE_TCGETATTR -DHIDE -DUSE_DIRENT -DSYS_UNIX -DHAVE_STDLIB -DUNIQUE_HISTORY -O3 -DNDEBUG -fPIC -I../js-1.7  -fPIC  js-1.7/jsarena.c



Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in GNU, Linux | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • How to build Python-4-Android for the ARM Neon
    Currently the Py4A project does not compile for the ARM Neon architecture. If you try to run ndk-build on the project by setting the APP_A...
  • Problems with new version of rpmbuild
    The Problem With the new version of rpmbuild installed on CentOS 6.x, if you try to use an old RPM spec file, you will get an error like the...
  • How to build the gcc Fortran cross-compiler for Android (ARM and x86)
    If you need to cross-compile for Android a program written in Fortran, you know already that the official Android NDK does not come with the...
  • Upgrading mid-2007 24in iMac with an SSD and a 2.5in HDD in the optical bay
    I own a mid-2007 24in iMac with a 2.4 GHz Intel Core 2 Duo processor, 4GB of DDR2 DRAM, running Mac OS Mountain Lion, and for the past few m...
  • Porting your Legacy C/C++ project to Android
    This is a recurring problem people have often: trying to port a big C/C++ project to the Android platform. You have thousands of lines of te...
  • How to inspect expanded C macros with gcc/gcc+
    Sometimes you get compilation errors in gcc/g++ and you'd like to inspect the output from the C compiler pre-processor to figure out why...
  • Android: Trying to load native library results in a process terminated by signal (11)
    Symptoms You are trying to load your native C/C++ library in an Android application and when at runtime your app calls the System.loadLibrar...
  • Arduino and 7-segment LED counter driven by two tactile switches
    I have posted on YouTube a couple of videos about a project I made with the Arduino prototype board. The circuit uses an Arduino mini and ...
  • How to build Python-4-Android for the x86
    Currently the Py4A project only compiles for the ARM architecture. The following patch for the python-build sub-directory allows you to cros...
  • How to port Mozilla SpiderMonkey 1.7 to Android
    Another third-party package I needed to cross-compile for Android was Mozilla's SpiderMonkey 1.7 Javascript engine. I found two issues h...

Categories

  • Android
  • Apple
  • Arduino
  • ARM
  • busybox
  • CentOS
  • DHCP
  • Fortran
  • GNU
  • GPON
  • iMac
  • Javascript
  • ksh
  • Linux
  • MacOSX
  • Mips
  • Network
  • Python
  • Router
  • UNIX
  • Windows
  • x86

Blog Archive

  • ▼  2013 (12)
    • ►  October (1)
    • ►  August (1)
    • ►  May (1)
    • ►  February (3)
    • ▼  January (6)
      • How to build Python-4-Android for the ARM Neon
      • How to build Python-4-Android for the x86
      • Android: Trying to load native library results in ...
      • How to port Mozilla SpiderMonkey 1.7 to Android
      • How to inspect expanded C macros with gcc/gcc+
      • Upgrading mid-2007 24in iMac with an SSD and a 2.5...
  • ►  2012 (11)
    • ►  December (2)
    • ►  November (2)
    • ►  October (7)
Powered by Blogger.

About Me

Unknown
View my complete profile