Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Kavrocks

macrumors newbie
Original poster
May 12, 2011
29
0
Hi,

I recently bought my first mac (used a PC all my life) and one of the first programs I installed was XCode 4. I have to say I've very mixed feelings about it.

I have been doing some programming in C and the IDE part is brilliant but have run into many problems and frustrations when it comes to compiling and running my programs. I was wondering if anybody would have any links to some good video tutorials for C programming/compiling/running in XCode 4. I've found some for older versions of XCode or some for different languages but I just want an easy to listen to tutorial that walks you through the basics of XCode and using it. I would prefer if the tutorial was not trying to teach me C/C++ programming.

Any help or suggestions you can give me will be greatly appreciated.
 
Frustration Ahoy!

You will have a long series of frustrations ahead. Not because Xcode or Objective-C or Cocoa are bad, but they are different from what you're used to.

Xcode is different from Visual Studio or Eclipse or whatever you've been used to. So there will be things that you're used to doing that Xcode either doesn't do or does differently. Frustration.

Objective-C is different from C++. It sounds like you're trying to stick with C++, which may be a good idea in the short term (to avoid the learning necessary to move to Objective-C). But you'll need to go to Objective-C at some point.

Cocoa is much different from Java or MFC or whatever set of classes you're used to. Frustration.

OS X is different from Windows.

I'm a big fan of Xcode/Objective-C/Cocoa/OS X, but they are different and you will have problems moving.
 
Once you get used to it you'll most likely really like it. I hated it at first, and wanted Visual Studio back but now I hate to even use Visual Studio and try and use Xcode for everything.
 
chown33 I did try googling it but got nothing that suited what I needed. I guess I'll just have to read the guides.

PatrickCocoa Yeah XCode has me very frustrated and I'd rather just get the hang of it than trying to figure it out and learn a new language. I'm coming from Visual Studio and its command line compiler.

chrono1081 I already went back to Visual Studio.

Thanks
 
Since you're programming C, you need to create a command-line tool project.

  1. Choose File > New > New Project.
  2. Select Application under Mac OS X on the left side of the New Project Assistant.
  3. Select Command-Line Tool from the list of application projects.
  4. Click the Next button.
  5. Choose C from the Type pop-up menu.
  6. Name your project in the Product Name text field.
  7. Click the Next button.
  8. Pick a location to save the project.
  9. Click the Create button.

Select a C file from the project navigator on the left side of the project window to edit the file. Click the Run button on the left side of the project window toolbar to compile and run the program. The debug area should open so you can see the output from the program, but if it doesn't open, choose View > Debug Area > Show Debug Area to show it.

Choose File > New > New File to add new C files to your project. Select the C and C++ group under Mac OS X on the left side of the New File Assistant to add a C or C++ file to your project.
 
C output

I have managed to set up a file for programming in C, but have still to work out where it outputs. Having moved recently from Codeblocks, I am used to it opening a command terminal with the output in. Any ideas?
 
Assuming your program is outputting to standard out using printf....

View > Debug Area > Activate Console (Shift + Command + C)
 
Xcode is very useful for objective C/cocoa programming, in particular for GUI stuff.

For C++ and other non GUI projects I still use Xcode as editor, but I use makefiles and the terminal to compile/run my code. You can configure Xcode to compile/run your C programs, but there will always be some manual work involved, since it's not what Xcode is designed for.

I'm still sad that support for pyObjC was dropped in version 4.2, I would have loved to use python for OSX GUI programming.

I found the Xcode/Cocoa tutorials that Apple provides somewhat confusing. But that's not what you were looking for anyways, right?
 
Objective-C is different from C++. It sounds like you're trying to stick with C++, which may be a good idea in the short term (to avoid the learning necessary to move to Objective-C). But you'll need to go to Objective-C at some point.

Sounds like they are trying to stay with "C" not "C++"
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.