Search code examples
c++architecturecompiler-errorsg++standard-library

g++ compilation of a separately preprocessed file gives error depending on the architecture


I am using g++ version 4.1.2 on a x64_86 GNU linux architecture. Code base is very huge and I don't have sufficient understanding of makefiles used in the project. The code compiles fine as it is.

For some debugging purpose, I need to preprocess (g++ -E) few source files individually and then re-compile it. I am giving the required include paths using -I. Ideally the compilation should go fine.

But I am getting few discrepancies in standard headers like:

  1. typedef unsigned long size_t; causes errors with operator new() declaration generated by compiler (if I change to unsigned int manually then this error disappears)
  2. In library functions like unsigned long numeric_limits<>::max(), compiler complains for big numbers such as 922...807L; it generates compiler error as integer constant is too large for long type
  3. Mismatch declaration of __errorno_location() gives compiler error

I am having hard time finding what is going wrong. Why compilation goes fine when I do make on unchanged file and why standard headers start cribbing when I give g++ -I <> -E option on individual file ?

(Note that there is no problem with the code we have written, it's just from standard library side. I tried locating the stddef.h which has unsigned int as typedef, but that just fixes the 1st problem. )

Any idea to fix this errors would be highly appreciated.


Solution

  • Don't preprocess and compile separately, or if you must then use consistent compiler options and a consistent environment.

    It sounds a though you're running the preprocessor on a 32-bit machine (or using the -m32 option) then compiling on a 64-bit machine.