XCode 4 C/C++ Tutorial

Discussion in 'Mac Programming' started by Kavrocks, Aug 12, 2011.

  1. Kavrocks macrumors newbie

    Joined:
    May 12, 2011
    #1
    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.
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
  3. PatrickCocoa macrumors 6502a

    Joined:
    Dec 2, 2008
    #3
    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.
     
  4. chrono1081 macrumors 604

    chrono1081

    Joined:
    Jan 26, 2008
    Location:
    Isla Nublar
    #4
    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.
     
  5. Kavrocks thread starter macrumors newbie

    Joined:
    May 12, 2011
    #5
    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
     
  6. szymczyk macrumors regular

    Joined:
    Mar 5, 2006
    #6
    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.
     
  7. weasel360 macrumors newbie

    Joined:
    Jan 8, 2012
    #7
    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?
     
  8. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #8
    Assuming your program is outputting to standard out using printf....

    View > Debug Area > Activate Console (Shift + Command + C)
     
  9. thundersteele macrumors 68030

    Joined:
    Oct 19, 2011
    Location:
    Switzerland
    #9
    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?
     
  10. stevetmq macrumors newbie

    Joined:
    Sep 15, 2009
    #10
    Sounds like they are trying to stay with "C" not "C++"
     
  11. MorphingDragon macrumors 603

    MorphingDragon

    Joined:
    Mar 27, 2009
    Location:
    The World Inbetween
    #11
    Look at the Visual Studio 11 Beta. Look at it and cry. UnrealScript Editor and UDK Kismet are more usable...
     
  12. chrono1081 macrumors 604

    chrono1081

    Joined:
    Jan 26, 2008
    Location:
    Isla Nublar
    #12
    Ok now I'm curious! I'll give the beta a whirl.
     

Share This Page