首页 > sublime text3 利用build system运行c++时的不解之处

sublime text3 利用build system运行c++时的不解之处

我之前一直用vs作为c/c++的学习环境,现在由于vs已经删除,就想用mingw+sublime进行学习
我按照网上的教程,安装了mingw和The GNU Compile suite,并对sublime进行了build system的配置,配置如下,这一段我是复制了网上的配置文件的

{
     "cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}"],
     "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
     "working_dir": "${file_path}",
     "selector": "source.c, source.c++",
     "encoding": "cp936",
     "shell": true,

     "variants":
     [
          {
               "name": "Run",
               //"cmd": ["CMD", "/U", "/C", "g++ ${file} -o ${file_base_name} && ${file_base_name}"] 
               "cmd": [ "start", "${file_path}/${file_base_name}.exe"]
          }
     ]
}

以下是我的测试代码

#include<iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    cout<<"asd"<<endl;
    int a=0;
    cin>>a;
    return 0;
}

该文件可以在sublime里正常编译,生成的exe程序也能正确运行,但当我使用sublime中的 运行 功能时,出现了下面的错误信息

[Compile D:\GitHub\python_study\s.cpp]

E: D:/GitHub/python_study/s.cpp:1 You can't use `macro parameter character #' in vertical mode #
E: D:/GitHub/python_study/s.cpp:1 Missing \begin{document}. #i
E: D:\GitHub\python_study\s.cpp:0 Emergency stop

3 errors, 0 warnings, 0 badboxes

[Finished in 0.06s]

请问这是什么意思?


编译指令要相应改变。第二行:

"cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}.exe"],

听我一言,用make吧,或者cmake。在类似Sublime的编辑器里只需要配置"make",尤其是当你在使用不同编辑器时,只需简单的配置。曾经整理过make的入门级常见使用方式,参见:http://harttle.com/2014/01/01/makefile.html

【热门文章】
【热门文章】