Help with Compiling large source file using g++

HI All,

I m compiling a 27 MB cpp file and compiler crashes.
My enviroment : RH 9, compiler g++

how i m compiling
g++ -fPIC -DWITH_OPENSSL -DWITH_COOKIES -c soapC.cpp

it took almost 30 -32 to throw error like report bug etc. I will post the same error, but if can any body tell how to compile large cpp file, is there any option/flag for g++ , i tried man g++ ,but couldn't find. It almost compile 97% of the file and then crashes throwing error.

Thanks & Regards.

Try the obvious solution: split it into multiple .cpp files and compile each on it's own. The dependencies between will have to be resolved by the linker, which will be called later anyways.

I have my doubts that a 27 megabyte source-file was generated by hand, so splitting it up may be as big a problem as compiling it...

You may be just plain running out of memory. Check how much swapping is happening while you're trying to build it.

Try playing with -O levels, it may be able to compile better without optimizations.

You could also split up the phases to prevent gcc trying to pipe them between multiple instances of itself. At the very least it would save you a bit of work on having to restart it completely from scratch every time it fails.

CXXFLAGS="-DWITH_OPENSLL -DWITH_COOKIES -fPIC"
# Preprocess
g++ ${CXXFLAGS} -E soapC.cpp -o soapC.i
# Compile
g++ ${CXXFLAGS} -c soapC.i -o soapC.o
# Link
g++ soapC.o -o soapC