views:

154

answers:

2

I have a static library that shares a lot of source between the OS X and Windows versions. Both versions use CMAKE. I have thought about a linux version due to recent requests.

  1. OS X and uses Carbon.

  2. Windows uses straign win32 API, no MFC

  3. is in C++ (.cpp)

My questions are:

  1. For the OS X version Apple is throwing away 64-bit Carbon, so can I mix Carbon and Cocoa classes in this library? Do I just change all files to .mm (For Objective-C which i need for Cocoa)

  2. If I change to .mm how does that affect Windows compilation?

  3. If I change to .mm how does it affect Linux?

Can anyone provide some insight on how to accomplish this task?

+1  A: 

I would really recommend against mixing Objective-C and C++. Although on OS X they both are compiled by GCC, thus making it possible, the Carbon and Cocoa libraries are not really meant to be mixed. Both Carbon and Cocoa are full and separate windowing libraries. However, in OS X 10.2, it is possible to mix them at the Window level (a Carbon app can host a Cocoa window), and anything later than 10.2 is supposed to be able to mix the libraries down to the widget level. So provided all of the users of your library are using an updated version of OS X, it is possible... I still don't recommend it. Plus then you have to link in all that extra code.

The effects of changing to .mm really depends on your compiler. I'm guessing you use gcc, since your library is going to be for all three platforms, so on gcc, the .mm code can be compiled as C++ as follows.

gcc -x c++ [sourcefile]
Davis Gallinghouse
+1  A: 

Apple published a good guide about mixing Carbon and Cocoa. Basically the two are orthogonal so you can mix them.

Anyway I do not think changing your .cpp to .mm to be a good idea at all, nor mixing C++ and Objective-C. Just start migrating to Cocoa in separate .m files.

EDIT: If you change .cpp to .mm you will not compile the files on the other platforms anymore. So my advice is to create the new Cocoa classes. Some of them will of course reference some c++ code, including c++ headers. Those will have the .mm extension.

IlDan
@llDan - Well, my reasoning is that some of the classes need changes and going Cocoa has benefits for these classes. Co are you saying keep existing functionality as .cpp and the new classes just make .mm?