【发布时间】:2019-08-22 22:42:50
【问题描述】:
我想使用 Sublime Text 3 构建系统自动运行 c++:
当我手动设置构建系统时它可以工作:
> Tools > Build System > C++11
我应该改变什么才能设置,
> Tools > Build System > Automatic
并运行 C++11?
C++11.build-system
{
"cmd": ["g++", "-std=c++11", "-o", "${file_path}/${file_base_name}", "${file}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"quiet": true,
"variants":
[
{
"name": "Run",
"cmd": ["bash", "-c", "g++ '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
},
{
"name": "Build without C++11",
"cmd": ["g++ '${file}' -o '${file_path}/${file_base_name}'"]
}
]
}
测试
#include <stdio.h>
int main()
{
printf("Hello World!\n");
}
输出(手动)
Hello World!
输出(自动)
[Finished in 0.1s]
我的猜测是它可能会使用,
> Tools > Build System > C++ Single File
C++ Single File.build-system:
// {
// "shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\"",
// "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
// "working_dir": "${file_path}",
// "selector": "source.c++",
// "variants":
// [
// {
// "name": "Run",
// "shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""
// }
// ]
// }
{
"cmd": ["g++", "-std=c++11", "-o", "${file_path}/${file_base_name}", "${file}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"variants":
[
{
"name": "Run",
"cmd": ["bash", "-c", "g++ '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
},
{
"name": "Run with C++11",
"cmd": ["bash", "-c", "g++ '${file}' -std=c++11 -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
},
{
"name": "Build without C++11",
"cmd": ["g++ '${file}' -o '${file_path}/${file_base_name}'"]
}
]
}
【问题讨论】:
-
在什么情况下它不起作用?乍一看,只要您第一次选择合适的变体,它就应该可以工作;如果你这样做了但它失败了,我的下一个猜测是使用
shell_cmd而不是cmd。另请注意,您的run变体不包括使用 C++ 11 的参数。
标签: c++ c++11 sublimetext3