[英]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.