2

My Problem: I am writing a chess engine in C++. Part of writing a chess engine is dealing with very large numbers (conceivably up to 2^63). I have a file that is running unit tests for my project, and when I try to run the build task to compile it to an executable, I am getting the following error:

C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/as.exe: C:\Users\chopi\AppData\Local\Temp\ccEvO3si.o: too many sections (32782)
C:\Users\chopi\AppData\Local\Temp\ccCF1XuS.s: Assembler messages:
C:\Users\chopi\AppData\Local\Temp\ccCF1XuS.s: Fatal error: can't write 293 bytes to section .text of C:\Users\chopi\AppData\Local\Temp\ccEvO3si.o: 'File too big'
C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/as.exe: C:\Users\chopi\AppData\Local\Temp\ccEvO3si.o: too many sections (32782)
C:\Users\chopi\AppData\Local\Temp\ccCF1XuS.s: Fatal error: can't close C:\Users\chopi\AppData\Local\Temp\ccEvO3si.o: File too big
The terminal process "C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command & 'C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\g++.exe' -g c:\Users\chopi\Desktop\chess-engine\maestro-tests\main.cpp -o c:\Users\chopi\Desktop\chess-engine\maestro-tests\main.exe" terminated with exit code: 1.

Basically, there are too many sections. So I go looking for an answer and find many places explaining how to configure bigobj for Visual Studio, but not for Visual Studio Code.

What I've tried: It should be as simple as passing either /bigobj, -bigobj, or both -Wa and -mbig-obj as options when compiling. So I've tried a number of things that should, but aren't, compiling my code with big objects enabled. This is how my tasks.json looks:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "C/C++: g++.exe build active file",
            "command": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

but I've also tried the likes of:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "C/C++: g++.exe build active file",
            "command": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
            "args": [
                "-g",
                "-bigobj",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

and

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "C/C++: g++.exe build active file",
            "command": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
            "args": [
                "-g",
                "-Wa",
                "-mbig-obj",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

...among others.

These configurations are yielding errors of g++.exe: error: unrecognized command line option '-bigobj' and

g++.exe: error: unrecognized command line option '-Wa'; did you mean '-W'?
g++.exe: error: unrecognized command line option '-mbig-obj'

, respectively.

What I'm wondering: So, is there a way I can resolve this "too many sections" error in Visual Studio Code? Or will I have to bite the bullet and configure everything for Visual Studio?

David Chopin
  • 2,780
  • 2
  • 19
  • 40
  • 1
    `-Wa,-mbig-obj` the comma matters – user4581301 Aug 12 '20 at 04:21
  • @user4581301 Doesn't work: `Missing argument in parameter list.` Not sure that's how the comma works in this case. For the tasks.json, we pass an array of options as strings. That comma would specify two separate options, I believe. – David Chopin Aug 12 '20 at 04:24
  • One argument. `-Wa` means pass the flag after the comma to the assembler. – user4581301 Aug 12 '20 at 04:26
  • https://gcc.gnu.org/onlinedocs/gcc/Assembler-Options.html#Assembler-Options – user4581301 Aug 12 '20 at 04:26
  • Interesting, not sure why passing `-Wa,-mbig-obj` as an option wouldn't result in an error. It doesn't seem to like the comma. – David Chopin Aug 12 '20 at 04:30
  • Maybe it needs to be escaped in some way? – David Chopin Aug 12 '20 at 04:31
  • Figured it out, but if you wanna add your own version of the answer, I can accept your version. You pointed me in the right direction @user4581301. – David Chopin Aug 12 '20 at 04:37
  • Feel free to self-answer. I only knew half of the problem. Anything I answered with won't get the whole problem solved. Actually please do self-answer. One of these days I might need to know how to do this, and I'm sure there are other people right now who do need to know. – user4581301 Aug 12 '20 at 04:38
  • Thanks a ton either way, got me looking in the right direction :) @user4581301 – David Chopin Aug 12 '20 at 04:42

1 Answers1

5

As user4581301 suggested, I had to not separate -Wa and -mbig-obj as two, independent options. Instead, I had to keep them as one option: -Wa,-mbig-obj. This ran into an error, but, per this answer, adding --% as the first argument, coupled with the aforementioned suggestion about the options, got my code finally compiling to an executable. Here is what the tasks.json looks like after the changes:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "C/C++: g++.exe build active file",
            "command": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
            "args": [
                "--%",
                "-g",
                "-Wa,-mbig-obj",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}
David Chopin
  • 2,780
  • 2
  • 19
  • 40