sublime text 2 c++编译 环境 问题小结

闲来无事,想要用subllime text 2 写下c++小程序,以前没用过这个编译c++,

期间出过很多问题,但是安装了sublime text 3 直接可以使用,前提安装了gcc/g++ 编译,没安装的去 安装下MinGW,然后在 环境变量把 MinGW下的bin 加入,

新建LIBRARY_PATH变量,如果有的话,在值中加入MinGW下的lib;新建C_INCLUDEDE_PATH变量,值设为MinGW下的include。

不过本着找问题解决问题,查了不少,最终成功在sublime text 2上跑起来了c++ 

其中遇到

1.Sublime Text 2 编译c++没反应

去找C:UsersAdministratorAppDataRoamingSublime Text 2PackagesDefault下的 exec.py中修改

os.environ["PATH"] =os.path.expandvars(path).encode(sys.getfilesystemencoding())

看一下你的exec.py的 40行是不是这个

45行 换成 proc_env[k] = os.path.expandvars(v.decode(sys.getfilesystemencoding())).encode(sys.getfilesystemencoding())

2.让Sublime text 2 的build系统支持中文路径和中文文件

Sublime text 2的build系统不支持中文路径,可以通过如下方式解决:

打开sublime_plugin.py文件(可以用Everything搜索)

添加以下内容:

reload(sys)
sys.setdefaultencoding('gbk')

3.Ctrl+shift+B 无法运行 

去C:UsersAdministratorAppDataRoamingSublime Text 2PackagesC++C++.sublime-build

修改

// "cmd": ["bash", "-c", "g++ '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
"cmd" : ["${file_path}/${file_base_name}"]

然后就可以正常运行了

4.Decode error - output not utf-8

去找C:UsersAdministratorAppDataRoamingSublime Text 2PackagesDefault下的 exec.py中修改

修改append_data 方法下的替换部分加粗部分

def append_data(self, proc, data):
if proc != self.proc:
# a second call to exec has been made before the first one
# finished, ignore it instead of intermingling the output.
if proc:
proc.kill()
return

is_decode_ok = True;
try:
str = data.decode(self.encoding)
except:
is_decode_ok = False
if is_decode_ok==False:
try:
str = data.decode("gbk")
except :
str = "[Decode error - output not " + self.encoding + "and gbk] "
proc = None

# Normalize newlines, Sublime Text always uses a single separator
# in memory.
str = str.replace(' ', ' ').replace(' ', ' ')

原文地址:https://www.cnblogs.com/liumianweifeng/p/3854853.html