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

问题描述

我的问题: 我正在用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-objtasks.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","-bigobj","isDefault": true
            }
        }
    ]
}

但我也尝试过以下方法

{
    "version": "2.0.0","-Wa","-mbig-obj","isDefault": true
            }
        }
    ]
}

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'

错误
"too many sections"

我想知道的是 因此,有什么方法可以解决 Visual Studio代码中的import * as functions from 'firebase-functions'; import * as admin from 'firebase-admin'; import * as WineModel from '../../src/app/tasting/wine/wine.model'; admin.initializeApp(); export const countGlogStat = functions.https.onRequest(async (req,res) => { const wines: WineModel.WineModel[] = []; try { const winesSnapshots = await admin.firestore().collection('wines').get(); winesSnapshots.forEach(winesnapshot => wines.push(winesnapshot.data())); } catch(err) { console.log('Error while getting wines',err); res.status(500).json({ custName: 'Error while getting wines',err }); } }); 错误吗?还是我必须忍痛为 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
            }
        }
    ]
}