如何设置makeprg使得Vim能编译C文件

78 views
Skip to first unread message

crb...@gmail.com

unread,
Jan 2, 2008, 9:49:01 AM1/2/08
to Vim.cn
我想让我在Vim中键入":make"后执行以下语句:
gcc.exe "D:\Cruby\VC++\a\abc.c" -o "D:\Cruby\VC++\a\abc.exe" -g3 -
I"D:\Study\Dev-Cpp\include" -L"D:\Study\Dev-Cpp\lib" -g3

我应该怎么弄呢?


我设成:
set makeprg=gcc.exe "%:p" -o "%:p:r" -I"D:\Study\Dev-Cpp\include" -
L"D:\Study\Dev-Cpp\lib"
后能编译成一个exe文件,但文件名为a.exe(估计是默认的),而不是我想要的文件名abc.exe,"%:p:r"我感觉没有起任何作用
(经试验,发现只要设成makeprg=gcc.exe就可以成生a.exe了)

还有就是设成:
set makeprg=gcc.exe\ -o\ %<\ %
结果出来:
|| C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/ccCycaaa.o(.text+0x0):adf.c:
multiple definition of `main'
|| C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/cc8Kbaaa.o(.text+0x0):adf.c:
first defined here
|| C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/ccCycaaa.o(.text+0xa2):adf.c:
multiple definition of `InsertSort'
|| C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/cc8Kbaaa.o(.text+0xa2):adf.c:
first defined here
|| C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/ccCycaaa.o(.text+0x17e):adf.c:
multiple definition of `ShellSort'
|| C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/cc8Kbaaa.o(.text+0x17e):adf.c:
first defined here
|| C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/ccCycaaa.o(.rdata+0x0):adf.c:
multiple definition of `ORIGIN_NUM'
|| C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/cc8Kbaaa.o(.rdata+0x0):adf.c:
first defined here
|| collect2: ld returned 1 exit status
也无法编译成一个exe文件,请问有人知道怎么设吗?


以下是我的_vimrc文件里的一些相关内容:
/*********** start ************************/
map <s-k> :make "%:p" <CR><cr>:copen<cr>
map <s-l> :close <CR>:!"a.exe" <CR>

"编译设置
set errorformat=%f:%l:\ %m
set makeprg =gcc\ "%:p"\ -o\ <\ %:p:r.exe
set shellpipe=>%s\ 2>&1
/************** end ***************************/

PS: 也问了一些人,告诉我可以用makefile解决,但我还是想知道不用makefile怎么解决~各位有知道的吗

freakie

unread,
Jan 23, 2008, 1:56:28 AM1/23/08
to Vim.cn
我用vc
set makeprg=nmake

#参考MAKEFILE:
NAME=WinMain
$(NAME).exe: $(NAME).obj resource.res
link $(NAME).obj resource.res kernel32.lib user32.lib gdi32.lib
winmm.lib
$(NAME).obj: $(NAME).c
cl /nologo /ML /W3 /GX /O2 /c $(NAME).c
resource.res: resource.rc
rc resource.rc
然后nmap <your key> :make
cmd下进入源码目录,gvim *.c后<your key>即可,希望能有帮助
Reply all
Reply to author
Forward
0 new messages