LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   vim and makefile (https://www.linuxquestions.org/questions/linux-general-1/vim-and-makefile-190297/)

melinda_sayang 06-06-2004 07:39 AM

vim and makefile
 
:set makeprg=make
:make
shell returned 2
(1 of 1): make: *** No targets specified and no makefile found. Stop.

Ok, I have a directory which has Makefile and source code file so when in the directory ( with console ), you could just type make to produce the binary. But how can I do that with vim?

Second question:
How could u compile single program with vim?
Assume in console, you do this:
g++ -o bla bla.cpp

Now you are editing bla.cpp, but you want to compile it with vim. How do you do that?

320mb 06-06-2004 08:03 AM

Quote:

Now you are editing bla.cpp, but you want to compile it with vim. How do you do that?
Uh, VIM is a text editor, not a compiler

hw-tph 06-07-2004 03:30 AM

Quote:

Uh, VIM is a text editor, not a compiler
Uh, vim is actually a full-blown IDE.

If the Makefile is working you should be able to just type :make in vim to compile it. This of course assumes that your current working directory is the one where the Makefile is located (this works just fine for me, I just verified it with a simple program). The error message seems to hint at you might not be in that directory.

To set the compiler and options for a simple c file (as an example), try this: :set makeprg=gcc\ -Wall\ -o\ outname\ %
The backslashes are necessary to escape the spaces, and the % character refers to the filename you are currently editing. So The above translates to gcc -Wall -o outname whatever.c.
When you have set your makeprg as you wish you can compile using make and show the error list with :cl, hop to the next error line using :cn and so on.

Hope that helps.

Håkan

melinda_sayang 06-07-2004 09:04 AM

Ok, that works. But I have to launch vim from the source code directory with console. But usually I launch gvim with icon then I open the source code file and the current directory is not source code directory. That means I cannot use "make" command anymore because the current directory is in $HOME directory ( I think ).

How to change the current directory in vim?

hw-tph 06-07-2004 02:03 PM

Heh, I had to check it for myself but this works:
:cd /wherever/the/directory/is
:make



Håkan

melinda_sayang 06-09-2004 07:20 AM

Ok, thank you. But that means I miss GTK+-2.4 feature, that is bookmark of GTK+ file selection. But nothing is perfect in this world.

But how can you run the binary?
:./a.out
:a.out
not working.......

hw-tph 06-09-2004 07:47 AM

To execute external commands you need to prepend them with an exclamation mark. :!./test to execute the program "test" located in the current directory.

I don't understand what you mean with the GTK+ bookmark at all. :o


Håkan

melinda_sayang 06-10-2004 12:16 AM

If you use GTK+-2.4 version, when you open file with gvim, you have bookmark feature. So you could record what directory are visited very often by you.

But thank you.


All times are GMT -5. The time now is 05:05 PM.