Hi, just started using Xcode to code C programs. Im trying to create multiple programs in the same source
folder but Im getting an error message.

When i select 'File' -> 'New File' -> '.C File' I can create the file fine: it creates the .c program and a header program (.h extension) But if I create this in the same source folder as another program neither will run.
I know the program is fine itself, they will compile when by themselves.
Whats the problem?

Do I need to create a new project for each C program - I don't think I would have to otherwise XCode isn't very good.

What you think?

Recommended Answers

All 4 Replies

No, you just have to change the linking. Before I tell you how to do this, though, I recommend you switch to Terminal + MacVim. Using an IDE in the beginning is overkill, as well as hiding certain aspects away from you.

Now, after you create a new file (again, if you're just starting out, I suggest you drop the .h file; that is, uncheck the option), you should see this in your project's main window. Just deselect the old file (in my case, main.c), and it should work. The build error is triggered by the linker, as you end up having two definitions of the same function (main).

No, you just have to change the linking. Before I tell you how to do this, though, I recommend you switch to Terminal + MacVim. Using an IDE in the beginning is overkill, as well as hiding certain aspects away from you.

Now, after you create a new file (again, if you're just starting out, I suggest you drop the .h file; that is, uncheck the option), you should see this in your project's main window. Just deselect the old file (in my case, main.c), and it should work. The build error is triggered by the linker, as you end up having two definitions of the same function (main).

Thanks that worked fine - Im used to programming using Java not so, Im only beginning again. But in order to use the "Terminal + MacVim" option, what do I have to do and what are the advantages of using this method instead of using the built in XCode application already found on Mac OS X?

Xcode hides lots of stuff from you. If your are going to be using C only for a couple of days then probably X code is the right way to go. But if you want to learn the language from ground up, then probably you want to explore the terminal option

Apart from Xcode hiding a lot from you, you will quickly find that Vim is a better editor than the ones integrated with the IDEs. And Xcode is more useful for projects, while right now you are only getting your feet wet with C, so, as you've already found out, there's a lot of bulk in for people just starting out.

In the end, the choice is yours, so choose the one you feel the most comfortable with.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.