如何编辑 Sublime Text 构建设置? [英] How to edit Sublime Text build settings?
问题描述
我想在 Ubuntu 12.04 上的 Sublime Text 3 的 C++ 单文件构建中启用 -std=gnu++11
.
I want to enable -std=gnu++11
in Sublime Text 3's C++ Single File build on Ubuntu 12.04.
我已经将工具链升级到最新的 g++ 并且不想在每次构建时看到以下错误:
I have already upgraded the tool chain to the latest g++ and do not want to see the following error on every build:
error: #error 此文件需要 ISO C++ 2011 标准的编译器和库支持.此支持目前处于实验阶段,必须使用 -std=c++11 或 -std=gnu++11 编译器选项启用.
error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
我浏览到 /home/myuname/.config/sublime-text-3
但找不到任何要编辑的文件.
I browsed to /home/myuname/.config/sublime-text-3
but cannot find any file to edit.
如何编辑构建设置?
推荐答案
已编辑
我的原始答案有效,但有更好的方法来做到这一点,即创建您自己的构建系统.这个用例正是该功能存在的原因.
My original answer works, but there's a much better way of doing this, by creating your own build system. This use case is exactly why the feature is there.
转到工具
→ 构建系统
→ 新建构建系统...代码>
(一直在底部)并输入下面的内容.另存为 C++ 11 Single File.sublime-build
,现在可以在构建系统菜单中访问它.选择它,点击 CtrlB 构建,然后点击 CtrlShiftB运行生成的程序.或者您可以使用 Build and Run
选项并通过点击 CtrlB 调用它,然后选择该选项.
Go to Tools
→ Build System
→ New Build System…
(all the way at the bottom) and enter the contents below. Save as C++ 11 Single File.sublime-build
, and it will now be accessible in the build system menu. Select it, hit CtrlB to build, and then hit CtrlShiftB to run the resulting program. Or you can use a Build and Run
option and call it by hitting CtrlB, then selecting that option.
{
"cmd": ["g++", "-std=gnu++11", "${file}", "-o", "${file_path}/${file_base_name}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"variants":
[
{
"name": "Run",
"cmd": ["${file_path}/${file_base_name}"]
},
{
"name": "Build and Run",
"cmd": ["g++ -std=gnu++11 ${file} -o ${file_path}/${file_base_name} && ${file_path}/${file_base_name}"],
"shell": true
}
]
}
如果您以后需要编辑它,该文件在Packages
的User
文件夹中.Packages
目录是选择 Preferences → Browse Packages…
时打开的目录:
If you need to edit it in the future, the file is in the User
folder of Packages
. The Packages
directory is the one opened when selecting Preferences → Browse Packages…
:
- Linux:
~/.config/sublime-text-3/Packages
或~/.config/sublime-text/Packages
- OS X:
~/Library/Application Support/Sublime Text 3/Packages
或~/Library/Application Support/Sublime Text/Packages
- Windows 常规安装:
C:\Users\YourUserName\AppData\Roaming\Sublime Text 3\Packages
或C:\Users\你的用户名\AppData\Roaming\Sublime Text\Packages
- Windows 便携式安装:
InstallationFolder\Sublime Text 3\Data\Packages
InstallationFolder\Sublime Text\Data\Packages
- Linux:
~/.config/sublime-text-3/Packages
or~/.config/sublime-text/Packages
- OS X:
~/Library/Application Support/Sublime Text 3/Packages
or~/Library/Application Support/Sublime Text/Packages
- Windows Regular Install:
C:\Users\YourUserName\AppData\Roaming\Sublime Text 3\Packages
orC:\Users\YourUserName\AppData\Roaming\Sublime Text\Packages
- Windows Portable Install:
InstallationFolder\Sublime Text 3\Data\Packages
InstallationFolder\Sublime Text\Data\Packages
确切路径取决于版本以及您是否从 Sublime Text 3 升级.
这篇关于如何编辑 Sublime Text 构建设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!