windows下在GVIM中使用gcc/g++编译调试c/cpp文件

来源:互联网 发布:管家婆软件试用 编辑:程序博客网 时间:2024/05/01 15:42

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文件的末尾增加编译调试选项,添加的代码如下:

[plain] view plaincopyprint?
  1. "定义CompileRun函数,用来调用编译和运行
  2. func CompileRun()
  3. exec "w"
  4. if &filetype == 'c'
  5. exec "!gcc -Wall -enable-auto-import % -g -o %<.exe"
  6. if &filetype == 'cpp'
  7. exec "!g++ -Wall -enable-auto-import % -g -o %<.exe"
  8. elseif &filetype == 'java'
  9. exec "!javac %"
  10. endif
  11. endfunc
  12. "结束定义ComplieRun
  13. "定义Run函数
  14. func Run()
  15. if &filetype == 'c' || &filetype == 'cpp'
  16. exec "!%<.exe"
  17. elseif &filetype == 'java'
  18. exec "!java %<"
  19. endif
  20. endfunc
  21. "定义Debug函数,用来调试程序
  22. func Debug()
  23. exec "w"
  24. if &filetype == 'c'
  25. exec "!gcc % -g -o %<.exe"
  26. exec "!gdb %<.exe"
  27. elseif &filetype == 'cpp'
  28. exec "!g++ % -g -o %<.exe"
  29. exec "!gdb %<.exe"
  30. elseif &filetype == 'java'
  31. exec "!javac %"
  32. exec "!jdb %<"
  33. endif
  34. endfunc
  35. ”设置程序的运行和调试的快捷键F5和Ctrl-F5
  36. map <F5> :call CompileRun()<CR>
  37. map <F6> :call Run()<CR>
  38. 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 去掉就好了

原创粉丝点击