gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 14:47:05 25 4
gpt4 key购买 nike

我的问题:我正在用 C++ 编写一个国际象棋引擎。编写国际象棋引擎的一部分是处理非常大的数字(可以想象高达 2^63)。我有一个正在为我的项目运行单元测试的文件,当我尝试运行构建任务以将其编译为可执行文件时,出现以下错误:

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.

基本上,章节太多了。所以我去寻找答案并 find many places explaining如何为 Visual Studio 配置 bigobj,但不为 Visual Studio Code 配置。

我尝试过的:它应该像传递 /bigobj-bigobj 或同时传递 -Wa-mbig-obj 一样简单> 作为编译时的选项。因此,我尝试了一些应该但没有的方法,在启用大对象的情况下编译我的代码。这是我的 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
}
}
]
}

但我也尝试过:

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

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

...等等。

这些配置会产生 g++.exe 错误:错误:无法识别的命令行选项“-bigobj”

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

分别。

我想知道的是:那么,有没有办法解决 Visual Studio Code 中的这个“太多部分” 错误?或者我是否必须硬着头皮为 Visual Studio 配置所有内容?

最佳答案

正如 user4581301 所建议的,我必须不将 -Wa-mbig-obj 作为两个独立的选项。相反,我必须将它们保留为一个选项:-Wa,-mbig-obj。这遇到了错误,但是,根据 this answer ,添加 --% 作为第一个参数,再加上前面提到的有关选项的建议,让我的代码最终编译为可执行文件。以下是 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
}
}
]
}

关于c++ - 在 Visual Studio Code 中编译 C++ 代码时如何设置 bigobj 选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63369666/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com