1. 首先下载安装MinGW,下载地址: http://sourceforge.net/projects/mingw/。这个是边下载边安装的,下载完成即安装完成。我的安装目录为D:\MinGW;
2. 设置系统环境变量。右击Computer -> Properties-> Advanced system settings -> Advanced -> Environment Variables。然后:
2.1 在PATH里加入D:\MinGW\bin ;
2.2 新建LIBRARY_PATH变量,如果有的话,直接加入D:\MinGW\lib ;
2.3 新建C_INCLUDEDE_PATH变量,值设为 D:\MinGW\include ;
2.4 新建CPLUS_INCLUDE_PATH变量,值为 D:\MinGW\include ;
3. 在_vimrc文件的末尾增加编译调试选项,添加的代码如下:
"定义CompileRun函数,用来调用编译和运行
func CompileRun()
exec "w"
if &filetype == 'c'
exec "!gcc -Wall -enable-auto-import % -g -o %<.exe"
elseif &filetype == 'cpp'
exec "!g++ -Wall -enable-auto-import % -g -o %<.exe"
elseif &filetype == 'java'
exec "!javac %"
endif
endfunc
"结束定义ComplieRun
"定义Run函数
func Run()
if &filetype == 'c' || &filetype == 'cpp'
exec "!%<.exe"
elseif &filetype == 'java'
exec "!java %<"
endif
endfunc
"定义Debug函数,用来调试程序
func Debug()
exec "w"
if &filetype == 'c'
exec "!gcc % -g -o %<.exe"
exec "!gdb %<.exe"
elseif &filetype == 'cpp'
exec "!g++ % -g -o %<.exe"
exec "!gdb %<.exe"
elseif &filetype == 'java'
exec "!javac %"
exec "!jdb %<"
endif
endfunc
”设置程序的运行和调试的快捷键F5和Ctrl-F5
map <F5> :call CompileRun()<CR>
map <F6> :call Run()<CR>
map <C-F5> :call Debug()<CR>
4. 完成上面几步基本上就大功告成了。
可能遇到的问题:
编译的时候可能会出现:
Info: resolving std::cout by linking to __imp___ZSt4cout (auto-import)
c:/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../../mingw32/bin/ld.exe: warning: a
uto-importing has been activated without –enable-auto-import specified on the c
ommand line.
This should work unless it involves constant data structures referencing symbols
from auto-imported DLLs.)
在编译命令中加入 -enable-auto-import
备注:以上大部分参考自网络,但是有点需要注意:
这种情况,把CompileRun()里面加红的 -Wall -enable-auto-import 去掉就好了