现在的位置: 首页 > 综合 > 正文

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

2018年12月25日 ⁄ 综合 ⁄ 共 1320字 ⁄ 字号 评论关闭

1,首先下载安装MinGW。

下载地址在http://sourceforge.net/projects/mingw/。这个"mingw-get-inst-20101030.exe"是边下载边安装的,下载完成即安装完成。我的安装目录是C:\MinGW。

2,设置环境变量。右击我的电脑,点属性->高级->环境变量。然后:

1) 在PATH里加入C:\MinGW\bin,记得,如果里面还有其他的变量,记得要加个分号啊,分号得在英文输入模式下输入的。
2) 新建LIBRARY_PATH变量,如果有的话,在值中加入C:\MinGW\lib,这是标准库的位置。
3) 新建C_INCLUDEDE_PATH变量,值设为C:\MinGW\include。
4) 新建CPLUS_INCLUDE_PATH变量,值为C:\MinGW\include

具体路径请根据你的MinGW选择。

3,在你的_vimrc文件中配置编译调试选项。

我的个人配置如下(在_vimrc文件尾行加入):

“定义CompileRun函数,用来调用进行编译和运行

func CompileRun()
exec “w”
“C程序
if &filetype == ‘c’
exec “!gcc -Wl,-enable-auto-import % -g -o %<.exe”
“c++程序
elseif &filetype == ‘cpp’
exec “!g++ -Wl,-enable-auto-import % -g -o %<.exe”
endif
endfunc
“结束定义CompileRun
“定义Run函数
func Run()
if &filetype == ‘c’ || &filetype == ‘cpp’
exec “!%<.exe”
endif
endfunc
“结束定义Run

“定义Debug函数,用来调试程序
func Debug()
exec “w”
“C程序
if &filetype == ‘c’
exec “!gcc % -g -o %<.exe”
exec “!gdb %<.exe”
elseif &filetype == ‘cpp’
exec “!g++ % -g -o %<.exe”
exec “!gdb %<.exe”
endif
endfunc
“结束定义Debug

4,完成上面几步基本上就大功告成啦,尽情享受vim编程吧。

可能遇到的问题:

编译的时候可能会出现:

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.)

在编译命令中加入 -Wl,-enable-auto-import 就行啦

抱歉!评论已关闭.