Mac os sublime运行c语言时常见的问题

首先你是否配置好C语言的环境了呢?首先介绍一下配置方法:

点开Tools -> Build System -> New Build System,然后会出现一个文件,我们输入以下内容:

{

“cmd”: [“bash”, “-c”, “g++ ‘${file}’ -o ‘${file_path}/${file_base_name}’ && osascript -e ‘tell application \”Terminal\” to activate do script \”clear&&${file_path}/${file_base_name} && read -p \\\”Press Enter to exit.\\\”&&exit\”‘”],

“file_regex”: “^(..{FNXX==XXFN}*):([0-9]+):?([0-9]+)?:? (.*){0}#x22;,

“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}'”]

}]}

然后保存,文件保存为c.sublime-build,接下来我们可以通过以下代码检验一下是否好用:

新建文件,然后将下面代码复制,接下来要对文件进行保存,切记一定要保存,好多小白容易犯这个毛病,然后我们需要切换编译系统:Tools -> Build System ->c,这个c就是我们刚刚配置好的c语言编译环境,然后command+B进行编译,编译后command+shift+B进行运行即可。

#include <stdio.h>
 
int main()
{
    printf("Hello, World! \n");
 
    return 0;
}

若大家使用command+B出现如下图问题:

错误

我们可以通过改变编译的方式,使用command+shift+g,然后点击build with:c进行编译,编译成功后同样使用command+shift+g,然后点击build with:c-run即可运行。

如有问题,欢迎一起讨论!

猜你喜欢

转载自blog.csdn.net/liaoningxinmin/article/details/88365890