how to use Vim to do c programming on OS X?

After downloading Vim,what else do I need to do to start c programming?Does the Terminal has any use here?

Posted on Aug 21, 2006 8:17 AM

Reply
13 replies

Aug 22, 2006 8:57 AM in response to tibago

hi tibago,

well you need a compiler of course, so download the XCode Tools and install them. http://developer.apple.com/tools/xcode/

this install provides two avenues in which to program. one is an IDE (integrated development environment - editor, compiler, debugger all in one, um, integrated environment) which is called XCode. it'll be sitting in /Developer/Applications.
the other is the standard 'linux' way. use vim (i use emacs) to edit text files, write a Makefile, then type make to build the app....

which approach you use depends a lot on what you're trying to do... HTH, cheers

Aug 22, 2006 9:01 AM in response to tibago

what is the meaning of "no target specified and no
makefile found" ?
it appears when i want to execute the programme.


sounds like a.) you haven't built it yet and b.) you don't yet have the tools you need to build it.
type 'which make' from terminal, does it return /usr/bin/make?
if not, don't have make installed. if make isn't installed, i bet you don't have any compilers either. type 'which gcc' or 'which g++'. are these in your path?

now. it might help if you gave more details about what you're trying to compile. after you un-tar.gz the sources, is there a "README" or an "INSTALL" file there that provides instructions?

as i said before, i think you need to start by installing the XCode tools first...
post back if you need any more help... cheers

Aug 23, 2006 8:11 AM in response to tibago

It sounds like it is time for a sanity check. Have you compiled C programs on Unix before? If not, there are a few steps to learn.

First of all, you need a program to compile. Start your vim (or just type vi - it is included with the OS) and enter the following:<pre>
#include <stdio.h>

int main()
{
printf("Hello World!\n");

return 0;
}</pre>
For more information about how to use VI, consult any one of several hundred VI cheat sheets. Basically, you have "command" mode and "edit" mode. Press i or a to enter "edit" mode. Press escape to return to "command mode". Type 'ZZ' in command mode to save and quit. For the above example, in command mode, type ":w hello.c". Then type 'ZZ' to quit.

Now you have a source file named "hello.c". To compile it, type:<pre>gcc hello.c</pre>
Now you have created an executable with the default file name of "a.out". To run it, type:<pre>./a.out</pre>
This tells the BASH shell to find the a.out program in the current directory and run it. You should get a nice message.

Next, give it a more meaningful name. Type:<pre>gcc -o hello hello.c</pre>Now you can type:<pre>./hello</pre>

You can create as many source files as you want and compile them all with:<pre>gcc -o myapp *.c</pre>

Once you get tired of recompiling all your files every time, you need to start using make. Here are complete instructions. As you can see, it can be "challenging". At this point, you might want to consider using Xcode. Try to write and compile the same program in Xcode.

Have fun!


iMac Mac OS X (10.4.6)

Aug 24, 2006 10:32 AM in response to tibago

I don't know. I've never typed ":make" in vim. I usually have a few terminal windows open and type "make" in one of those.

Perhaps you should re-phrase your question and explain what you are trying to accomplish. I can't really tell what your level of expertise is so I don't really know what level of response I should give. In your previous post, it seemed like you had never used Unix before. Now, it sounds like you know more about vim than I do. I'm confused.

Aug 25, 2006 6:29 AM in response to tibago

A makefile is a special file that tells make how to build your project. You need to know how to build your project without make in order to write a makefile. It breaks your project down into its individual components and lists each piece's dependencies so everything gets built in the right order.

How did you build your code in Windows? if you typed :make, then there was a makefile. I'm a little confused how you can get used to using :make and not know about makefiles. Is this a project you're starting from scratch? or are you trying to compile something you downloaded? is there a "configure" file in the code root?

Here's some links to get you started:
http://mrbook.org/tutorials/make/
http://www.hsrl.rutgers.edu/ug/make_help.html
http://makepp.sourceforge.net/1.18/t_simplest.html

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

how to use Vim to do c programming on OS X?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.