C++ programming using Xcode

Discussion in 'Mac Apps and Mac App Store' started by markoibook, Aug 3, 2004.

  1. markoibook macrumors regular

    Joined:
    Jan 28, 2004
    Location:
    Reading, UK.
    #1
    Hi all,

    I have knowledge of C and want to start learning C++. Traditionally, I am a Windows Programmer, but want to start coding apps for Mac OS X. What is the best approach to programming using C++ on OS X?
    From what I gather only carbon can be used with C++ - but carbon is designed for backward compatability with OS 9/8/etc - but I am not interested in this. Cocoa is OS X only (which I like), but requires objective C. However, I would rather learn C++, as this is widely used in the Windows world, so I believe that C++ would be more useful to learn than Obj-C. Would it be possible for anyone to confirm whether it would be possible to program Cocoa using C++?
    Also, does anyone know of any good Mac Development websites that have good step by step tutorials to programming in C++ using Xcode?

    Cheers for your help!!!
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    You can use Cocoa via Objective-C++ but you still need to write quite a lot of plain Obj-C to get it all to tie together. Carbon is not just for backward compatability. It's an equaly valid choice.
     
  3. jsw Moderator emeritus

    jsw

    Joined:
    Mar 16, 2004
    Location:
    Andover, MA
    #3
    Hi, sorry to be brief - on conference call for work - but wanted to provide you with a quick answer, and, if possible, more details later.

    You can use C++ within Xcode. it supports the syntax. Since you want to use Cocoa, you'll want to use Objective-C++.

    Quick link to one mention of it.

    You'll ultimately end up using Objective-C to interface with Cocoa elements, but you can write most of your code in C++.
     
  4. jsw Moderator emeritus

    jsw

    Joined:
    Mar 16, 2004
    Location:
    Andover, MA
    #4
    I'm am at the very beginning - just entering the door - of Mac programming (well, did it for a year or two with System 7, but that was completely different...).

    My understanding of Carbon vs Cocoa is that Carbon is necessary if you want your app to run on OS 9 and OS X, but that it has less access to the OS X innards than Cocoa. If not true, what is the big plus to Cocoa?
     
  5. Sayer macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX
    #5
    You can get extra features that are part of Cocoa such as interactive spell checking as you type, but that is not inherit to Mac OS X's "innards". Cocoa is a high-level application framework that has a lot of pre-made features (spell checking) built on top of Mac OS X.

    To be honest you can make a simple app in Carbon with as little code as a Cocoa app would require.

    But most software is not a "simple" app and thus the amount of custom code increases with the amount of features you want the app to have, in either Cocoa or Carbon.

    Today Carbon is lightyears ahead of the Classic Mac OS in terms of what it does for you automatically. You can use Core Graphics, Core Audio in a Carbon app just like Cocoa. You can make custom UI elements in Carbon relatively easily with HIView (Mac OS X 10.2 and newer).

    Carbon apps can have Toolbars and Drawers (which are horrendous and poor additions to the Mac UI IMHO), just like Cocoa apps.

    You can even mix Carbon code inside Cocoa apps or vice versa.

    There are various aspects of Mac OS X that *require* using Cocoa/Objective-C, such as WebKit (the HTML rendering engine of Safari) no matter which programming language you want to use.

    So in the end use whatever language you want. If you want an application framework that uses C++ take a look at CodeWarrior and its PowerPlant framework. Or any of the other up-to-date C++ application frameworks such as Qt that offer Mac OS X compatibility without requiring the use of Objective-C. BTW the Qt framework is cross-platform, Cocoa isn't.

    Anyone who says Mac OS X *requires* the use of Cocoa to make an app of any significance simply doesn't know what they are talking about i.e. they are very new to the platform or only learned Objective-C/Cocoa as their first language.

    You could even use X11 and straight UNIX-ported code if you wanted and it would be "Mac OS X native" in that it executes natively on the OS without any emulation (unless you consider the X11 libraries to be emulation instead of an API layer on top of Quartz/Core Foundation/Carbon/Cocoa).
     
  6. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    Both sit on top of CoreFoundation, CoreGraphics (and Quartz) and a few other things:

    [​IMG]

    They have different strengths. Cocoa is a pure Object-Oriented environment in which amazingly rapid development is possible. It provides access to a lot of the system, but there is not, for example, a pure Cocoa way to access Quicktime (you end up going through Carbon). Carbon on the other hand is procedural (i.e. designed for C). You can use C++ with it, but the Carbon environment itself is not very O-O. As both sit on top of CoreFoundation it is posible (with a little coersion) to do things like create a window in Carbon then use Cocoa to talk to it.

    Cocoa provides some language features that are not available in C++ (Catagories for example) as well as access to some really funky technology like Cocoa Bindings. It does some much of the hard work for you that it seems like cheating to start with.
     
  7. jsw Moderator emeritus

    jsw

    Joined:
    Mar 16, 2004
    Location:
    Andover, MA
    #7
    My "fondest" memory of System 7 coding was having to deal with windows that spanned monitors of differing depths - i.e., one was 32-bit, the other was greyscale. I suppose that's not an issue anymore... both because it's handled for you and because almost no one uses sub-32-bit displays anymore. ;)
     
  8. markoibook thread starter macrumors regular

    Joined:
    Jan 28, 2004
    Location:
    Reading, UK.
    #8
    Thanks guys - I wasn't expecting such a big response!

    I think that I might take the C++ with Carbon approach, as the main aim of the exercise is to learn C++ and to also make some OS X apps (remember I used to be a Windows Programmer).

    Does anyone know of any good sites with tutorials for C++ and carbon, and any good books?

    I found the currency converter example on the Apple Dev site - which was a useful introduction as to how to use the Interface builder - but it didn't explain where the C++ code came from!

    Thanks again! :)
     
  9. jsw Moderator emeritus

    jsw

    Joined:
    Mar 16, 2004
    Location:
    Andover, MA
    #9
    Also, my thanks to all for explaining the differences! Sorry, markoibook, but it's been 5 years since I programmed C++, so any books I'd recommend would be grossly out-of-date. Now, if you were learning Java, it'd be a different story. ;-)
     
  10. markoibook thread starter macrumors regular

    Joined:
    Jan 28, 2004
    Location:
    Reading, UK.
    #10
    I dabbled with Xcode and Java last year - after getting infuriated with the sluggish response of netbeans on my iBook.

    I found Xcode great for developin Java Applets - though I maybe interested in doing some native OS X Java programs with Cocoa or Carbon. ;)
     
  11. CPlusPlusMan macrumors newbie

    Joined:
    Jun 30, 2008
    #11
    unfortunately X-Code and the entire OS X developer tool chain are geared toward Obj-C cocoa developers (big mistake imho) to the near complete neglect of C++ programmers. I personally prefer Qt and C++ over the cocoa toolchain because I'm not forced to do everything visually in order to do things easily, I can build the interface purely in code and C++ and it makes sense and ultimately looks good in terms of layout. It's mostly carbon for now but it's slowly converting over to cocoa and looking native in it's look and feel. This will be fully available and supported in all it's 64bit glory in Qt 4.5 where you will have the option of accessing either carbon or cocoa interchangeably. You will also be able to access cocoa classes and the Obj-C language from the QMacCocoa container class. Unfortunately you really have to hack up XCode to support the Qt library fully. on my computer, I have it set up so that there's a Qt Project you can make that will let you use the same template for hard coded interfaces and ui file interfaces, the help system for Qt is integrated with XCode, and ui files in the XCode projects when double clicked open up in Qt Designer. If you want to write full featured applications on the Mac in C++, this is by far your best option. despite the protests of most mac programmers who would tell you to turn 2 this year and learn to use cocoa and it's associated crayons (Interface Builder which magically allows you to graphically build and wire your interfaces (bleck)). for more information on Qt, go to www.Qtsoftware.com. I also highly recommend the Qt programming guide by Blanchette and Summerfield (C++ GUI programming with Qt 4). Good luck!
     
  12. dws90 macrumors regular

    Joined:
    Jan 16, 2008
    #12
    I sincerely hope he was able to figure something out in the past four and a half years...
     
  13. CPlusPlusMan macrumors newbie

    Joined:
    Jun 30, 2008
    #13
    <fake yell that devolves into laughter>It still comes up in google searches!!! LOL</fake>
     
  14. QueenZ macrumors 6502

    QueenZ

    Joined:
    Oct 26, 2008
    #14
    You can also use tools to make cross-platform softs in C++ for Windows Linux and Mac... but if you want to develop only for Mac then Xcode is the way to go..
     
  15. CPlusPlusMan macrumors newbie

    Joined:
    Jun 30, 2008
    #15
    Ya, but the garsh-darn thing is geared toward the Smalltalk/C with NeXTSTEP libraries through the emacs editor crowd... i'm sorry, I learned C++ and I like being able to handcode my interfaces, and I use vim. It's like XCode was made to piss off programmers like me who don't prefer doing things the way apple would like to force everyone to do them. and the Elitist attitude given by a lot of the Mac programmers I've met really pisses me off and makes me want to punch them in the nose... they're lucky they're sitting behind a computer screen because if someone got as snarky as they usually do with me, I'd punch them hard in the face for being *******s. and I'm sick of apple standing behind them because they do things their control freakish lazy way. I'm a programmer god-damnit, not a 2 year old with programming crayons. Give me code or stop trying to get people to make programs for your platform. It's not like Apple can't bind Cocoa to C++ and provide an easy way to hard code interfaces, Qt is proof of that. they're just too prideful to give us programmers that convenience... and for that I have to say that Apple truly hates any programmer that doesn't drink their elitist koolaid. saying "yes, you are the best, you let me be lazy and make applications using drag and drop and click drag and barely any coding! isn't life grand, I don't have to do the thing that I'm passionate about anymore!". It's BS.
     

Share This Page