2

Similar question with no real answer applicable to my case : CLICK
Question which I researched before asking here - CLICK

I'm using MinGW64 to try and compile a very large .cpp file (>13k lines), but I also have access to Visual Studio 2010 - if someone has a solution using that, feel free to tell me.
I've identified an error in the assembling stage -

... too many sections (33396)
C:\Users\username\AppData\Local\Temp\ccnAocvD.s: Assembler messages:
C:\Users\username\AppData\Local\Temp\ccnAocvD.s: Fatal error: can't write 
CMakeFiles/source.dir/sourcecode.cpp.obj: File too big

I'm currently running the compilation with the -Os , --param ggc-min-expand=0, --param ggc-min-heapsize=4096 as suggested by two of my colleagues - the compilation is running way over 5 hours now.

Update:

As suggested by some people, I will just split the file into 2 source files and create a header for them - thanks.

Second Update:

Compilation hasn't finished yet(5 days !!!), even after creating a header and splitting the file into 4 smaller ones.

Final

This problem remained unresolved - even after following advice from everyone that posted I still couldn't manage to compile this.

Community
  • 1
  • 1
baibo
  • 448
  • 4
  • 20
  • What is the issue with "separate those methods that call each other," That is normal C/C++ file structure – mmmmmm Jul 09 '13 at 13:59
  • Well, I have a method called `foo` that calls method `bar` inside - if I put `foo` in `file1.cpp` and bar in `file2.cpp` I get a compilation error. – baibo Jul 09 '13 at 14:01
  • 3
    To me, 13K lines doesn't seem that big. Are you sure it's not a case of your file doing something strange - e.g. including the same file recursively forever, or something like that? – Mats Petersson Jul 09 '13 at 14:03
  • It's an open source file that is supposed to be a very large library of functions - it doesn't have any recursion inside it and other people have used it, so I will rule that one out. – baibo Jul 09 '13 at 14:07
  • 1
    @startfish re foo and bar you need a header file to declare the function that is missing – mmmmmm Jul 09 '13 at 14:40
  • Splitting very large source files is a best practice, not "suicide". Just do it. – Fred Foo Jul 09 '13 at 14:43
  • did splitting files work? – A. K. Jul 14 '13 at 18:43
  • Nope - I split the file into 4 smaller files and it's been compiling since Wednesday... The problem is that I tried compiling with optimisations(i.e. flag -O3) and it got through but I got linker errors. I've simply abandoned this task – baibo Jul 14 '13 at 18:52
  • If your compilation hasn't finished in ... well, an hour (but I'd expect it to be more like ten minutes or less; 13k lines isn't all that big, though it is not small), it probably isn't going to. Are you doing any Template Metaprogramming? How many headers are you including in those files? How big is the file generated by `g++ -E`? What does `gcc -H` tell you about the headers included? What happens when you compile without any optimization (or the `--param` arguments)? Is your machine a reasonable development platform (say 2+GHz CPU, 2+ cores, 4+GiB RAM)? – Jonathan Leffler Jul 14 '13 at 19:12
  • 1
    Do a "binary search" on your original file: split in 2 halves and compile each **separately**. Unless there are several problems, one half should compile rather quickly and the other one should get stuck. Continue with it in the same manner - split in half etc. - until you find the offending code. – SomeWittyUsername Jul 14 '13 at 19:31
  • Just make sure all the header files have include guards(http://en.wikipedia.org/wiki/Include_guard). – A. K. Jul 23 '13 at 22:13
  • @JonathanLeffler As far as I'm concerned, the code made use of templates, but not template metaprogramming (I wasn't familiar with the term before reading your post, but I googled it and I don't think it's being used). The # of headers included is around 100. I'll get back to you with the `g++ -E` and `g++ -H` when I'm at work because I don't have the source code here. ALso my machine has 8 CPUs and 12 Gib Ram. – baibo Aug 05 '13 at 19:34

1 Answers1

1

Not sure about GCC, but have you tried the /bigobj flag for that specific file in VisualStudio?
I had the same issue with a large file, and it actually solved the issue. So it's worth a try.

From MSDN:

By default, an object file can hold up to 65,536 (2^16) addressable sections. This is the case no matter which target platform is specified. /bigobj increases that address capacity to 4,294,967,296 (2^32).

More about this here.

Macmade
  • 52,708
  • 13
  • 106
  • 123