简体   繁体   English

在 Visual Studio Code 中编译 C++ 代码时如何设置 bigobj 选项?

[英]How to set bigobj option when compiling C++ code in Visual Studio Code?

My Problem: I am writing a chess engine in C++.我的问题:我正在 C++ 中编写一个国际象棋引擎。 Part of writing a chess engine is dealing with very large numbers (conceivably up to 2^63).编写国际象棋引擎的一部分是处理非常大的数字(可能高达 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 .所以我 go 寻找答案并找到很多地方解释如何为Visual Studio配置bigobj ,但不是为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.我试过的:它应该像在编译时传递/bigobj-bigobj-Wa-mbig-obj作为选项一样简单。 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:这就是我的tasks.json样子:

{
    "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 '-bigobj'

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 ?我想知道的是:那么,有没有办法可以解决Visual Studio Code中的"too many sections"错误? Or will I have to bite the bullet and configure everything for Visual Studio ?还是我必须硬着头皮为Visual Studio配置一切?

As user4581301 suggested, I had to not separate -Wa and -mbig-obj as two, independent options.正如 user4581301 建议的那样,我不必将-Wa-mbig-obj作为两个独立的选项分开。 Instead, I had to keep them as one option: -Wa,-mbig-obj .相反,我不得不将它们作为一种选择: -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:这是tasks.json更改后的样子:

{
    "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
            }
        }
    ]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Visual Studio Code中编译C ++代码 - Compiling C++ code in Visual Studio Code 如何在visual studio中设置compile flag / bigobj? - How to set compile flag /bigobj in visual studio? 在 Visual Studio Code 中编译 Hello World C++ 代码 - Compiling Hello World C++ Code in Visual Studio Code 编译C ++程序时在Visual Studio代码中包含错误 - Include error in visual studio code while compiling a C++ program C++ Visual Studio 代码不与工作区中的单个文件夹一起编译 - C++ Visual Studio Code Not Compiling with Individual Folders in Workspaces 在Visual Studio 2013上编译旧的C ++代码 - Compiling old C++ code on Visual Studio 2013 为什么我的Visual Studio 2013的C ++代码编译速度很慢 - why my visual studio 2013 is slow for c++ code compiling 在Visual Studio中编译不需要.net安装C ++的代码 - Compiling code in Visual Studio that does not require .net to be installed C++ 在 Visual Studio Code 中调试 C++ 时如何读取输入? - How to read input when debugging in C++ in Visual Studio Code? 在带有“运行而不调试”选项的 Visual Studio Code 中运行 C++ 程序时出现错误消息 - Error message when running C++ programs in Visual Studio Code with "Run Without Debugging" option
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM