20

I am looking for alternatives for my current box and Mac OS X seems very appealing.

My main area of interest is C++ programming. Currently I'm using Eclipse + CDT and g++ for creating my software; sometimes it is KDevelop.

I know that primary IDE for Mac is Xcode and primary language is Objective-C. I would like to avoid learning Objective-C if at all possible. I've also heard/read that there are some issues in accessing Mac OS X APIs from C++.

Hence my question: what is the complete solution for developing/debugging/testing C++ applications that access all aspects of hardware (UI, sound, video/accelerated video, etc.) for Mac OS X?

Edit: how does Xcode compare to the Eclipse+CDT combo? If this comparison is at all possible...

5
  • XCode handles C++ perfectly well. I think it is a bit of an over-statement that Objective-C is the primary language. Objective-C would be the primary language for developing the GUI portion of an application but not required. Mar 11, 2009 at 18:06
  • @Martin, Objective-C would be required for a Cocoa application, if I'm not mistaken.
    – Robert S.
    Mar 11, 2009 at 18:23
  • 1
    btw. I also read that Objective-C is a niche language used only by Apple; so is it really worth the effort to learn all of it?
    – Marcin Gil
    Mar 12, 2009 at 7:14
  • 2
    Yes it is. It is just a part of smalltalk on top of c, so there is not that much effort. It is a niche language used in the fastest growing market segment. Jan 15, 2010 at 23:26

14 Answers 14

20

If you want to use C++ instead of Objective-C, and still want to avoid an intermediate layer of libraries (such as QT), you can use Carbon.

I would use XCode instead of Eclipse simply because Eclipse is way slower when dealing with hardcore C/C++ programming (compiling, debugging, testing).

When I first started to program in Mac OS X, I was in the same page you are now. I thought it was better to stick to the language I knew (C++) and use an older library (Carbon). For some reason I don't remember now, I forced myself into Cocoa (Objective-C). Looking back, I think it was a good thing because:

  1. Objective-C is not fundamentally different to C++
  2. Cocoa is better, faster and simpler than Carbon
  3. iPhone Dev is exclusively Cocoa (Carbon is not supported)
2
  • 20
    -1 For new application development, going Carbon is really bad advice. Mar 11, 2009 at 23:58
  • 19
    Read the question. What would you use if you want to code C++ GUI applications in Mac OS X? Jan 15, 2010 at 11:53
6

I've been playing around using Objective-C++ to write the UI, making it easier to use C++ to write the application back-end. It seems to work pretty well for me. Objective-C & Objective-C++ are pretty easy to pick up and this lets me keep using my hard-won C++ knowledge.

6

You should not avoid learning Objective-C and Cocoa. It should in fact be the first thing you do. Unless you have a solid background in Smalltalk, you're unlikely to have been exposed to a large (set of) framework that is as well-designed.

2
  • This is not a "complete solution for developing/debugging/testing C++ applications." It's an unrelated opinion, and not even a partial solution, let alone a complete one. Mar 24 at 4:42
  • However, with hindsight it is the correct answer. And has been since 2009. Bad Stackoverflow ideas about moderation don't influence that. Apr 3 at 10:19
5

Objective-C is not that hard. If you know C++ it will take you a day or three of applied effort to learn the conventions.

The Cocoa APIs and conventions take longer, but those come in time.

Good luck!

4

Unless you're looking at using an intermediate layer like QT, I think you're pretty much stuck with Objective C to interface with parts of the API like the GUI as it is their native language.

That said, it has been mentioned that you can easily mix Objective-C code and C++ code so you may still be able to write the majority of your application in C++.

I'm mainly a C++ programmer but I'm always dabbling in other languages and I've had a play with XCode (yes, I've got a Mac). I liked it, it's a bit different but as a way of nailing together an OS X GUI it's superb and the rest is between you and your favourite editor if you don't like XCode that much.

2
  • My idea is that Linux, which I use now, is very fractured/split when it comes to GUI implementations and APIs. Mac seems a very promising platform.
    – Marcin Gil
    Mar 11, 2009 at 13:19
  • I'm pretty much in the same boat - I'm a longtime Unix/Linux user and developer but I've never really been tempted to write GUI apps for either. And OS X seems to be the best of both worlds with a superb consistent GUI and Unix underneath. Mar 11, 2009 at 13:25
3

It's no problem using gcc or g++ from OS X. The XCode install gives you these compilers anyway, and if you really wanted, you could load up an x server instance and get KDE working. I like the XCode editor myself though. Eclipse also works with OS X, so you should be able to use your current environment.

I've used an OS X box for cross-compiling C code from PPC arch to ARM arch before, with no problems. It's just another *nix style system, so all the tools you are familiar with will already exist, and if they don't, just use fink or macports to get them yourself.

Also, if you really wanted to use C++ for developing GUI OS X apps, you could always use Carbon instead of Cocoa. It's a perfectly viable choice, only slightly deprecated.

2
  • With introduction of LGPLed QT I am more and more keen on using it.
    – Marcin Gil
    Mar 11, 2009 at 13:21
  • 3
    Learning Carbon is a bad idea. Everything for which there is a cocoa equivalent is effectively deprecated, and the carbon gui apis will never be 64-bit clean. It's much better to use Objective-C++ to interface with Cocoa, and use Carbon only where absolutely necessary.
    – user57368
    Mar 11, 2009 at 15:05
3

C++ works very well with Xcode. If you want cocoa, you can learn a minimal (and I mean really minimal) amount of Obj-C for the gui layer and have the bulk of your code in C++.

Another option is using one of the scripting language frameworks for hooking into the Cocoa API (such as PyObjc) and the bulk of your logic in C++.

The third and final option is using a cross platform gui kit such as Qt4. If there's a desire to make your libraries cross platform, this would be the route to go.

I would recommend against going with Carbon. It's definitely a dying beast. You could also use combinations of the above providing a library with your C++ code then creating gui specific UI's that link them them.

2

Carbon on Mac OS X is effectively deprecated - it does not and will not support 64 bit apps.

If you really really want to use c++, use Qt Creator

Which is now free and the trolltech SDK includes Qt 4.5, which while it is a c++ framework it internally uses Objective-C to interact with MAC OS X, so then you are not limited by Carbon.

The downside is that the trolltech libraries are not standard on the mac, you must provide them with your app.

2

I agree with Pablo Santa Cruz and would like to add that it's trivial to mix Objective-C with C++ in the same app (and the same source file). This is referred to as Objective-C++ and discussed in this article.

XCode compiles with GCC so you have Objective C, C, and C++ ready at your finger tips.

1

For some small hobby projects, and an iPhone app I'm making, I'm using a mix of objective C++ and 'real' C++. XCode supports the mixing of both languages fairly well. I use objective C/objective C++ for the user interface and as a thin layer between the OSX frameworks and my own code. So far, this has turned out to be a great way of working.

1
  • Oh, and as a small addition to my own answer: It's worth learning ObjC/ObjC++! The language is easy to learn, powerful and allows some very interesting constructs when used with the OSX frameworks. OSX programs can be as polished on the inside as they look on the outside.
    – Emiel
    Mar 12, 2009 at 15:43
0

I haven't used it on OSX myself (I can recommend it on Windows), but the Code::Blocks C++ IDE is implemented using, and supports, the cross-platform wxWidgets GUI library. It is supported on OSX - see this page.

0

I would advice you to stick with whichever IDE you are most comfortable with. Personally, I hated Xcode the first time I used it and refused to give up Eclipse. After a few days, I warmed up to Xcode and don't mind using it from time to time. However, I still use Eclipse whenever possible.

Just remember that you cannot write Cocoa applications using only C++, you need to dive into Obj-C for that. Carbon applications don't quite look or behave like a Cocoa app. Most people won't really mind but it's something to think about. I jumped into Obj-C from java/C# without any issues. The language takes a little getting used to but it's not very difficult.

0

The development environment that I am using right now for development in the Mac is QTCreator which is a free IDE for development in QT with gcc as compiler. It gives all the features I need and it is cross platform (one requirement of the application I am developing).

I have to say that I've been fairly impressed. I didn't have high hopes for such a focused (specifically designed for QT) and recent IDE. The environment is easy but powerful (including GUI editing) and has the better code completion I've ever seen. It is a breeze programming in this environment and don't miss a bit Visual Studio.

Really worth a try.

0

If you really want to use C++ on Mac OS X, use something like SDL / wxWidgets / Qt.

There's the option of combining Objective-C with C++, called Objective-C++. You could use it for all your model-stuff and just use Objective-C for the stuff, that isn't possible without the Foundation-framework.

As a last option, Carbon comes to mind. This is a native framework that was used in the pre-OSX times but runs on Mac OS X. The problem is, it's not supported for newer technologies and I think the next release of OS X, Snow Leopard, isn't going to support it at all.

Apple says:

Carbon enables C/C++ developers to take advantage of Mac OS X features, including the Quartz 2D graphics library, an efficient event-handling mechanism, and multiprocessing support. In addition, other industry-standard C/C++ APIs are available to Carbon developers, providing access to such services as the OpenGL drawing system, the Mach microkernel, and BSD operating-system services.

Don't expect Carbon applications to look 100% native and it's much more complicated for programming than Cocoa.

However, I recommend learning Objective-C, it's not hard and there are lots of powerful frameworks like CoreData, CoreGraphics and the like.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.