如何在VS代码中添加自定义编译命令?
我通常会在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代码中使用相同的设置。 到目前为止,我设法将编辑器和终端并排携带,并通过f1
和f2
。 但是我无法设置自定义 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在 VS 中设置
自定义任务
代码。编辑工作区.vscode
文件夹中的tasks.json
文件,如下所示:您可以将编译命令直接写入
"command"
属性中,或者将其与更多命令一起写入脚本中,然后在属性中写入简单的执行脚本命令。并且
"isDefault": true
属性使此默认任务
可以通过简单地与 ctrl+shift 绑定来调用+B。You can set a
custom task
in VS Code. Edit thetasks.json
file in the.vscode
folder of your workspace like: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 thisdefault task
which could be invoked simply binding with ctrl+shift+B.