![](/img/trans.png)
[英]How can I debug a .exe from the command line with a .exe generated from cl.exe (Visual Studio C/C++ Compiler)?
[英]Specify command-line C++ version for cl.exe (Visual Studio Code)
我正在測試 Visual Studio Code 中的 C++17 fallthrough屬性。 IDE 已配置為使用 Microsoft Visual Studio cl.exe 編譯器編譯 C/C++ 代碼。 我在 DEBUG 模式下構建簡單.cpp
文件的任務定義(在tasks.json
中)是:
{
"type": "shell",
"label": "cl.exe: Build active file",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/Fe:",
"${file}",
"/link",
"/OUT:${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$msCompile"
]
}
這已經在幾個程序上進行了測試並且運行良好。 現在我使用新的[[fallthrough]];
包含一個switch
語句; 屬性和編譯器生成:
warning C5051: attribute 'fallthrough' requires at least '/std:c++17'; ignored
將"/std:c++17",
添加到 cl.exe 的“args”中沒有任何改變(生成相同的編譯器警告)。 這是新版本:
"args": [
"/Zi",
"/EHsc",
"/Fe:",
"/std:c++17",
"${file}",
"/link",
"/OUT:${fileDirname}\\${fileBasenameNoExtension}.exe"
],
據我所知,根據用於指定語言標准的Microsoft 文檔,我的語法是正確的。
我究竟做錯了什么?
我在搜索其他內容時發現了這個問題,但這里有一個適合你的解決方案:)。
您的問題是您提供 arguments 的順序。 /Fe:
期待文件路徑緊隨其后 - https://docs.microsoft.com/en-us/cpp/build/reference/fe-name-exe-file?view=msvc-160
這是從 VSCode文檔中獲取的示例args
部分,但我添加了/std:c++17
編譯器標志
"args": [
"/Zi",
"/EHsc",
"/std:c++17", // <= put your compiler flag here
"/Fe:", // <= /Fe: followed by the path + filename
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}"
]
希望這會有所幫助,快樂的編碼!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.