WinGW——配置sublime 3运行C程序

1、下载WinGw

提示:

(1)MinGW-4.1.1.exe安装时(这里只是安装”current”,不安装”source”)下载以下几个包:
    ada.tar.gz
    binutils.tar.gz
    g++.tar.gz
    g77.tar.gz
    gcc.tar.gz
    java.tar.gz
    runtime.tar.gz
    w32api.tar.gz
    objc.tar.gz
    mingw32-make.tar.gz

    如果你水平可以,完全可以单独下几个自己需要的包配置一下,而不需要安装在(1)里如上配置

    出现管理界面时,选择第三项,再点击Installation—>Apply Changes. 

    (2)配置环境变量:
    PATH                           C:\mingw\bin;%PATH% (千万别直接覆盖PATH变量,务必将其放在最前面,要用分号隔开)
    LIBRARY_PATH               C:\mingw\lib
    C_INCLUDEDE_PATH        C:\mingw\include

    INCLUDE                        C:\mingw\include
    CPLUS_INCLUDE_PATH     C:\mingw\include\c++\3.4.5;C:\mingw\include\c++\3.4.5\mingw32;C:\mingw\include\c++\3.4.5\backward;C:\mingw\include

                                       (不同版本的c++版本不同,不要盲目照转,如安装不同的MinGW版本, 清注意配置)

    (3) 将C:\mingw\bin下的文件“mingw32-make.exe”复制一份并改名为“make.exe”,方便以后操作。


    测试:

    (1)在cmd中执行下make命令(如c:\mingw\bin>make.exe),如果出现“***No targets specfied and no make file found stop”,设置成功。
    (2)在cmd中输入“gcc -v”,如果屏幕出现“gcc不是内部命令或外部命令,也不是可运行的程序或批处理文件。”表示环境变量设定有问题。

        如果出现如下显示,表示设定成功。


        H:\>gcc -v
        Reading specs from C:/mingw/bin/../lib/gcc/mingw32/3.4.5/specs
        Configured with: ../gcc-3.4.5-20060117-3/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32

        --target=mingw32 --prefix=/mingw --enable-threads -le-sjlj-exceptions --enable-libgcj --disable-java-awt

        --without-x --enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter --enable-hash-synchroni
        Thread model: win32
        gcc version 3.4.5 (mingw-vista special r3)
        H:\>


    (3)在cmd中输入“mingw32-make -version”或者是"make -v",如果屏幕出现:


    H:\>mingw32-make -version
    GNU Make 3.81
    Copyright (C) 2006  Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.
    There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
    PARTICULAR PURPOSE.

    This program built for i686-pc-mingw32

    H:\>make -v
    GNU Make version 3.79.1, by Richard Stallman and Roland McGrath.
    Built for i686-pc-msys
    Copyright (C) 1988, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000
            Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.
    There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
    PARTICULAR PURPOSE.

    Report bugs to <bug-make@gnu.org>.

2、修改sublime3

以管理员身份运行sublime text 3,进入菜单工具-à编译系统-à新编译系统
输入如下内容,并将文件保存为CPP.sublime-build(注意不要修改文件名和大小写)。
{
"cmd": ["g++", "${file}", "-o","${file_path}/${file_base_name}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:?(.*)$",
"working_dir": "${file_path}",
"encoding":"cp936",
"selector": "source.c",
"variants":
[
{
"name": "Run",
"cmd": ["cmd","/C","start","cmd","/c", "${file_path}/${file_base_name}.exe &pause"]
}
]
}

3. 测试。编译之前在工具—>编译系统选择CPP。自己在SublimeText写一个C++程序,ctrl+b为编译;ctrl+shift+b为编译后在CMD里运行。如下图,中文和英文都正常显示。

# include<stdio.h>
int main(){
	printf("hello");
	return 0;
}
Ctrl+B是编译,Ctrl+Shift+B是在命令行里运行。注意选择:工具—>编译系统—>CPP

问题一:sublime text 编译时提醒[WinError 2] 系统找不到指定的文件

解决:环境变量没配置好,系统找不到gcc。MinGW的安装目录中的bin目录的路径填入PATH环境变量。重启程序,就可以解决了。


展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客
应支付0元
点击重新获取
扫码支付

支付成功即可阅读