在 Sublime Text 2 (gcc) 中编译和 运行 C
Compile and run C in Sublime Text 2 (gcc)
我在我的 Windows 8.1 机器上从 MinGW 网站安装了 gcc(仅 gcc),如果从命令提示符或 PowerShell 使用它,它可以完美运行。
但是我在使用 Sublime Text 2 编译和 运行ning C 程序时遇到了问题。如果我只编译它(工具 -> 构建),它就可以完美运行,并且我得到了我想要的可执行文件。 .exe 有效(即,如果我 运行 它手动它完美地工作)。问题是,如果我执行工具 -> 运行,Sublime Text 将不起作用。我在 Sublime 中收到此错误消息:
[Error 2] The system cannot find the file specified
[cmd: [u'bash', u'-c', u"gcc 'E:\Desktop\Test\HelloWorld.c' -ansi -pedantic -Wall -o 'E:\Desktop\Test/HelloWorld' && 'E:\Desktop\Test/HelloWorld'"]]
[dir: E:\Desktop\Test]
[path: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Skype\Phone\;C:\MinGW\bin]
[Finished]
一位教授向我们提供了以下我用来创建 Sublime Build 文件的代码(他使用 Mac,这可能是问题所在吗?):
{
"cmd": ["gcc", "-ansi", "-pedantic", "-Wall", "${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": ["bash", "-c", "gcc '${file}' -ansi -pedantic -Wall -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
}
]
}
我试着寻找以前问过的问题并找到了几个,但其中 none 包括我想使用的 gcc 开关:-ansi -pedantic -Wall .另外问题中提供的答案打开了一个新的命令提示符window来执行.exe文件,而我想在Sublime自己的输出中看到执行window.
提前致谢
如 this article 所述,您可以创建自己的构建系统文件:
{
"cmd": ["gcc", "${file}", "-o", "${file_path}/${file_base_name}.exe", "-ansi", "-pedantic", "-Wall"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.cpp, source.c++",
"path": "C:/PATH/TO/GCC/OR/MINGW/bin",
"shell": true,
"variants": [
{
"name": "Run",
"cmd": ["gcc", "${file}", "-o", "${file_path}/${file_base_name}.exe", "-ansi", "-pedantic", "-Wall", "&", "${file_path}/${file_base_name}.exe"]
}
]
}
我在我的 Windows 8.1 机器上从 MinGW 网站安装了 gcc(仅 gcc),如果从命令提示符或 PowerShell 使用它,它可以完美运行。 但是我在使用 Sublime Text 2 编译和 运行ning C 程序时遇到了问题。如果我只编译它(工具 -> 构建),它就可以完美运行,并且我得到了我想要的可执行文件。 .exe 有效(即,如果我 运行 它手动它完美地工作)。问题是,如果我执行工具 -> 运行,Sublime Text 将不起作用。我在 Sublime 中收到此错误消息:
[Error 2] The system cannot find the file specified
[cmd: [u'bash', u'-c', u"gcc 'E:\Desktop\Test\HelloWorld.c' -ansi -pedantic -Wall -o 'E:\Desktop\Test/HelloWorld' && 'E:\Desktop\Test/HelloWorld'"]]
[dir: E:\Desktop\Test]
[path: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Skype\Phone\;C:\MinGW\bin]
[Finished]
一位教授向我们提供了以下我用来创建 Sublime Build 文件的代码(他使用 Mac,这可能是问题所在吗?):
{
"cmd": ["gcc", "-ansi", "-pedantic", "-Wall", "${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": ["bash", "-c", "gcc '${file}' -ansi -pedantic -Wall -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
}
]
}
我试着寻找以前问过的问题并找到了几个,但其中 none 包括我想使用的 gcc 开关:-ansi -pedantic -Wall .另外问题中提供的答案打开了一个新的命令提示符window来执行.exe文件,而我想在Sublime自己的输出中看到执行window.
提前致谢
如 this article 所述,您可以创建自己的构建系统文件:
{
"cmd": ["gcc", "${file}", "-o", "${file_path}/${file_base_name}.exe", "-ansi", "-pedantic", "-Wall"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.cpp, source.c++",
"path": "C:/PATH/TO/GCC/OR/MINGW/bin",
"shell": true,
"variants": [
{
"name": "Run",
"cmd": ["gcc", "${file}", "-o", "${file_path}/${file_base_name}.exe", "-ansi", "-pedantic", "-Wall", "&", "${file_path}/${file_base_name}.exe"]
}
]
}