开发者

How to compile from gVim on Windows with GCC from Cygwin and then run the program?

I've been working at this all morning and I still can't find a way to easily bind a key to compile my program from the Windows version of gVim using the Cygwin GCC, and then run it. I'm kind of a novice to Bash scripting, and I haven't been able to make it create the .exe in the home directory (C:/cygwin/home) and then run it.

What I have so far:

map <F4> :call CompileRunGcc()<CR>
func! CompileRunGcc()
    exec "w"
    exec "!gcc /home/%:t && cd C:/cygwin/home && ./a.exe"
e开发者_运维问答ndfun

This would work all well and good, except that when I go to the home directory, the a.exe is not there. Compiling using gcc from the bash script .bat in cygwin works fine... but not from gVim.

Thanks for all help in advance.


check this plugin.

it seems to be what you want. I haven't tested it though.


For mono-files projects, you don't need any makefile. Thus, as long as gcc and make are in your $PATH, and you are in the directory where the current source file comes from, you "just" have to type:

:update
:make

If your program has no error, a simple !./%< will do. Otherwise, you may then have to execute a :copen to see compilation errors. If you have any, you'll notice some pathnames in *nix format. Unfortunately (g)vim-win32 is unable to understand them. That where my old cygwin compiler plugin skeept told you about comes into play. In order to support any compilation-like program (and not just make), it evolved into BuildToolsWrapper -- its installation will require lh-vim-lib, and may be a few other plugins of mine (system_tools, searchinruntime).

With it, just do once a :BTW add cygwin before you play with :make, or even :Make that BTW defines. This new command will do a :update! before calling :make with a automagically determined target. NB: BTW maps Make and the execution of the current project executable to <F7>and to <C-F5>.

PS: if you have have several files in your project, define a Makefile, and play with :make, that's all. PPS: you may also be interested into cyg-wrapper.sh that helps to correctly open gvim-win32 from cygwin shell.


Basically, when gcc runs it produces binary right in the working directory. If you want to place the output binary in a different directory you have to pass the -o options. So the command should be either of these:

exec "!gcc -o C:/cygwin/home/a.exe /home/%:t && cd C:/cygwin/home && ./a.exe"
exec "!cd C:/cygwin/home && gcc /home/%:t && ./a.exe"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜