views:

63

answers:

3

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"
endfun

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.

+2  A: 

check this plugin.

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

skeept
It's no longer maintained. Since then, I've opted for another solution that permits to compile with whatever cygwinish program (gcc, doxygen, latex, etc) and still transform the generated pathnames to something that vim32-(g)vim will understand -> http://code.google.com/p/lh-vim/source/browse/#svn/BTW/trunk
Luc Hermitte
Yeah, I tried that plugin and it didn't work. I didn't know what the error was either, so I gave up on that method.
David B
A: 

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"
tungd
+1  A: 

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.

Luc Hermitte