如何在VS代码中添加自定义编译命令?

发布于 2025-01-19 07:10:33 字数 716 浏览 3 评论 0原文

我通常会在Geany IDE中进行竞争性编程,并具有以下CODILE compile 命令来编译C ++程序 -

g++ -std=c++17 -Wshadow -Wall -o "%e" "%f" -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG

compile 命令由f9 key键入。我只需要按f9来保存和编译文件,然后切换到bash终端(f2键快捷方式)即可执行二进制文件。 终端还遵循编辑器中打开的当前文件的路径。

我希望在VS代码中使用相同的设置。 到目前为止,我设法将编辑器和终端并排携带,并通过f1f2。 但是我无法设置自定义 compile 命令,使用f9键绑定并配置终端,以便它遵循当前焦点中的编辑器中的文件路径。 br> 请给我一个完整的解决方案。直接编辑JSON设置文件会更好。
这是我吉尼(Geany Ide)中设置的快照: - 这就是我的geany外观和设置框的方式

I usually do competitive programming in Geany IDE and have the following custom compile command to compile C++ programs -

g++ -std=c++17 -Wshadow -Wall -o "%e" "%f" -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG

The compile command is binded by f9 key. I just have to press f9, which saves and compiles the file and then I switch to bash terminal (f2 key shortcut) to execute the binary file.
The terminal also follows the path of the current file opened in editor.

I want the same settings in VS Code.
So far, I have managed to bring the editor and terminal side by side and to easily toggle the focus between them via f1 and f2.

But I am unable to set the custom compile command, bind it with f9 key and to configure the terminal so that it follows the path of file in editor currently in focus.
Please give me a complete solution. It would be much better to edit the json setting files directly.
Here is a snapshot of the settings in my Geany IDE :-
This is how my Geany looks and the Setting boxes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

战皆罪 2025-01-26 07:10:33

您可以在 VS 中设置自定义任务代码。编辑工作区 .vscode 文件夹中的 tasks.json 文件,如下所示:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "My build task",
            "type": "shell",
            // Assign output file name with VSCode inner variables like ${fileBasename}
            "command": "g++ -std=c++17 -Wshadow -Wall -o ${fileBasename} -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG",
            "options": {
            },
            "problemMatcher": ["$gcc"],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

您可以将编译命令直接写入 "command" 属性中,或者将其与更多命令一起写入脚本中,然后在属性中写入简单的执行脚本命令。

并且 "isDefault": true 属性使此默认任务可以通过简单地与 ctrl+shift 绑定来调用+B

You can set a custom task in VS Code. Edit the tasks.json file in the .vscode folder of your workspace like:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "My build task",
            "type": "shell",
            // Assign output file name with VSCode inner variables like ${fileBasename}
            "command": "g++ -std=c++17 -Wshadow -Wall -o ${fileBasename} -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG",
            "options": {
            },
            "problemMatcher": ["$gcc"],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

You can write the compile command directly into "command" attribute, or write it with more commands into a script then write the simple executing script command in the attribute instead.

And the "isDefault": true attribute make this default task which could be invoked simply binding with ctrl+shift+B.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文