# Help with Compiling large source file using g++

**URL:** <https://community.unix.com/t/help-with-compiling-large-source-file-using-g/246963>\
**Category:** Programming\
**Created:** [August 13, 2009, 9:41am UTC](https://community.unix.com/t/help-with-compiling-large-source-file-using-g/246963 "2009-08-13T09:41:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![helpmeforlinux](https://community.unix.com/letter_avatar/helpmeforlinux/32/6_449c533f586939b6e5f246632a46421f.png) [@helpmeforlinux](https://community.unix.com/u/helpmeforlinux)\
**Post date:** [August 13, 2009, 9:41am UTC](https://community.unix.com/t/help-with-compiling-large-source-file-using-g/246963/1 "2009-08-13T09:41:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pludi](https://community.unix.com/user_avatar/community.unix.com/pludi/32/1278_2.png) [@pludi](https://community.unix.com/u/pludi)\
**Post date:** [August 13, 2009, 10:01am UTC](https://community.unix.com/t/help-with-compiling-large-source-file-using-g/246963/2 "2009-08-13T10:01:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/6_449c533f586939b6e5f246632a46421f.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [August 13, 2009, 11:58am UTC](https://community.unix.com/t/help-with-compiling-large-source-file-using-g/246963/3 "2009-08-13T11:58:56Z")

</div>

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.

```nohighlight
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

```
