Forums | MacLife
You are not logged in.
#1 2008-01-18 2:23 pm
Xcode - how to compile, seems simple...
I've started a C Programming course and I'm trying to use Xcode to do the examples in the book. I started a new empty project, created a source files folder in my project, created a source file, and wrote a hello world program. All of that was pretty similar to what we did in class on the Windows boxes with M$ Visual Studio 2008. Now I'd like to compile this program in Xcode and run it. I can't though because the Compile menu option is greyed out. The Build and Build And Go buttons are also greyed out.
I've tried searching in the help menu for "compile" and all it shows is the greyed out menu items as well as something about voice commands.
What am I missing?
Also, if someone could tell me how I can fix the header template so that it shows information like which assignment I'm working on, the due date, teacher's name, etc. I'd appreciate that as well. Right now it just reads:
Code:
* chapter1.c * chapter1 * * Created by "XXname removedXX" on 1/18/08. * Copyright 2008 __MyCompanyName__. All rights reserved.
Offline
#2 2008-01-18 3:15 pm
Re: Xcode - how to compile, seems simple...
I'm no Xcode guru, but my guess is you need to tell Xcode how to compile the program (it has no idea what kind of program it is). You're probably better off choosing a better option (e.g. C-command line, probably). Or just pop open Terminal and type:
Code:
gcc -o chapter1 chapter1.c
I always found Xcode too complicated for anything other than a full-blown project.
Basseq is me, John Whittet.
(Finishing the remainder of the thought expressed in the post has been left as an exercise for the reader.)
Offline
#3 2008-01-18 3:46 pm
Re: Xcode - how to compile, seems simple...
Yes, I realize that I can pop over to the terminal and type
Code:
cc chapter1.c
As the class continues though, we will be working on more complex programs and the use of an IDE such as Xcode will become helpful if not necessary. So, I'd like to learn how to use it now so that I may become accustomed to it as opposed to later when a term project or something of the ilk comes along.
Offline
#4 2008-01-18 6:00 pm
- aquaajb
- the official collectors edition

- From: USA
- Registered: 2002-08-07
- Posts: 265
Re: Xcode - how to compile, seems simple...
I recently used xcode to create my first real application (1k lines). Before that and in all my classes, I just used a text editor and terminal. I really think you'll find that a stand alone editor and terminal is your best bet for now. Nothing is going to get *too* complex in an introductory class, and xcode will probably just create more headaches than it solves at the level you're working on. One [headache] that comes right off the top of my head, for example, is to get at standard output with xcode you have to use Console..Terminal obviously just does it right there. Plus, unix experience is very useful!
Offline
#5 2008-01-18 7:53 pm
- Booksley
- Planely insane!
- From: Toronto, Ontario
- Registered: 2001-02-16
- Posts: 4787
Re: Xcode - how to compile, seems simple...
loaf wrote:
Yes, I realize that I can pop over to the terminal and type
Code:
cc chapter1.cAs the class continues though, we will be working on more complex programs and the use of an IDE such as Xcode will become helpful if not necessary. So, I'd like to learn how to use it now so that I may become accustomed to it as opposed to later when a term project or something of the ilk comes along.
Stick with a text editor and the terminal, seriously. XCode will hinder you more than it'll help you.
Offline
#6 2008-01-19 1:09 pm
Re: Xcode - how to compile, seems simple...
I could *never* get the GLU and GLUT libraries to work with Xcode. I stuck with Visual Studio on XP.
Basseq is me, John Whittet.
(Finishing the remainder of the thought expressed in the post has been left as an exercise for the reader.)
Offline
#7 2008-01-19 2:25 pm
Re: Xcode - how to compile, seems simple...
GLU is part of OpenGL. GLUT is a separate library, but all you have to do is right click on the "External Frameworks and Libraries" group on the left hand side of your project, and go to Add->Existing Frameworks..., navigate to System/Library/Frameworks (it might already be there by default, depending on your version), and select GLUT.framework. That should then allow you to link to the GLUT framework. (edit: actually, OpenGL isn't included by default either, so you will need to include it using the same instructions as GLUT, except selecting OpenGL.framework) All the headers can be included with "#include <GLUT/glut.h>" since glut.h includes the OpenGL headers for you. (I don't remember if it includes the glu headers, though, which would be included by "#include <OpenGL/glu.h>") For a third party framework located elsewhere, all you have to do is drag it into that folder (or any other, for that matter), and make sure it's set up to use your current target. For third party frameworks you have the added requirement where sometimes you need to place it in a special location relative to your executable based on how it was set up, but I think you can always put it in one of the Frameworks directories either in /Library or ~/Library, or you can use a command line tool to change where your executable looks for the framework.
loaf: if you post the project, I can take a quick look and see if I can tell you what's wrong with it and how to fix it. As mentioned, however, the most likely problem is you set up a truly empty project without an executable. If this is the case, you can go under New Target under the Project menu, and create a "Shell Tool" under the BSD section. You must then add your source files under the "Compile Sources" portion of that target.
Last edited by akb825 (2008-01-19 2:28 pm)
Offline
#8 2008-01-19 3:09 pm
Re: Xcode - how to compile, seems simple...
Thanks AKB. I know I tried a bunch of different things and could never get it working. I'm not doing OpenGL work anymore, but I may try to port some old projects to Xcode for the hell of it and see if this works.
Basseq is me, John Whittet.
(Finishing the remainder of the thought expressed in the post has been left as an exercise for the reader.)
Offline
#9 2008-01-20 4:46 pm
Re: Xcode - how to compile, seems simple...
I think the problem is you created a new empty project. If you do this, then you have to manually tell XCode how to compile all the files.
For standard C programming, you need to create a new command line tool.
EDIT: To be precise: File-->New Project-->Command Line Utility->Standard Tool.
(This in XCode 1.5)
Last edited by Metacell (2008-01-20 5:23 pm)
...having nothing in them of the feelings or principles of '76, now look to a single and splendid government of an aristocracy, founded on banking institutions and moneyed incorporations under the guise and cloak of their favored branches of manufactures, commerce and navigation, riding and ruling over the plundered ploughman and beggared yeomanry. -- TJ
Offline
#10 2008-01-22 12:47 am
Re: Xcode - how to compile, seems simple...
It's easier just to add a target to the current project rather than create a whole new project. (as I mentioned in my last post)
Offline
#11 2008-02-27 1:52 am
Re: Xcode - how to compile, seems simple...
I'm back. It's been a busy few weeks what with class, work, a neck injury, and a car accident... Sorry for looking like I was ignoring this...
Now that the class has moved on, I'm having trouble just using the terminal as suggested. The teacher gave us an additional source file and a header file to improve scanf. It basically handles some error checking. For example, if the user is asked to enter an integer and they enter xxx85xxx, scanf would just read in the 85 or if only letters are entered, other errors crop up. So I have these additional files.
I don't know of a way to have the terminal include these in the compile of the main source code file for the labs.
And when I used the above suggestions of creating a "Shell Tool" or "Command Line Utility->Standard Tool", then added the two files to the Source folder within the project, I get an error upon build saying "__snscanf_s", referenced from: which causes the build to fail.
Is there a simple guide somewhere to walk me through setting up a simple C program in Xcode?
Offline
#12 2008-02-27 5:00 am
Re: Xcode - how to compile, seems simple...
1. Open XCode.
2. Select File-->New Project-->Command Line Utility->Standard Tool (in XCode 3.0)
3. main.c will be created for you. You may of course edit, rename, or delete it.
4. To add new source files, right click on the icon at the top of the left-hand column with your project name, and select Add...->Existing Files.
5. It shouldn't matter how you organize your files, but to be precise, you should probably add them to the Source subcategory under your project name, which you can show by clicking the arrow next to the icon.
6. When all your source/header files are in your project, click the hammer icon with the green arrow on it.
7. Debug, unless lucky, in which case jump for joy.
EDIT: Oh, missed the part with the new error messages, see following post. Did you remember to use #include and stuff?
Last edited by Metacell (2008-02-27 7:20 pm)
...having nothing in them of the feelings or principles of '76, now look to a single and splendid government of an aristocracy, founded on banking institutions and moneyed incorporations under the guise and cloak of their favored branches of manufactures, commerce and navigation, riding and ruling over the plundered ploughman and beggared yeomanry. -- TJ
Offline
#13 2008-02-27 11:27 am
Re: Xcode - how to compile, seems simple...
If you are getting errors, it would be best if you print out the entire error. It would be even better if you post a zipped folder containing the XCode project and the code, that way we can look at it and see if something's wrong.
Offline
#15 2008-02-29 9:48 pm
Re: Xcode - how to compile, seems simple...
Yeah, you you pretty much have to upload files to an external site. Do you mind zipping it rather than putting it in a sitx archive? (you can just right click on the folder and select "Compress "folder name"", or "Create archive of "folder name"" based on what version of OS X you have) It's a lot more portable than sitx, and you generally don't have to search for a software download...
Offline
#16 2008-02-29 10:03 pm
- FutureDreamz
- 1.1.2.3.5.8.13.21.34.55

- From: カナダ
- Registered: 2007-01-07
- Posts: 4502
Re: Xcode - how to compile, seems simple...
Do you mind zipping it rather than putting it in a sitx archive? (you can just right click on the folder and select "Compress "folder name"", or "Create archive of "folder name"" based on what version of OS X you have) It's a lot more portable than sitx, and you generally don't have to search for a software download...
++
The amout of people that use Stuffit is gradually decreasing (I think), as fo example here i use The Unarchiver for virtually anything (except .sitx, as that hasn't been decoded yet) the Mac can't handle
Last edited by FutureDreamz (2008-02-29 10:11 pm)
Thanks for clicking.
Offline
#17 2008-02-29 10:41 pm
#18 2008-02-29 11:09 pm
Re: Xcode - how to compile, seems simple...
Your problem is it is making a call to _snscanf_s, which is a Microsoft only function. The solution is to replace the body of vsscanf_s with the following code:
Code:
int vsscanf_s (const char * src, const size_t length, const char * format, va_list argList)
{
return vsscanf(src, format, argList);
}This function is cross platform and will compile and run on a Mac. (as well as other platforms)
Offline
#19 2008-02-29 11:52 pm
Re: Xcode - how to compile, seems simple...
Thanks! That worked like a charm!
Now I just have to figure out the rest of Xcode.... It's weird, I know more about the Microsoft program that we use in class than the Apple program. Usually it's the other way around.
Last edited by loaf (2008-02-29 11:52 pm)
Offline

