What are some guidelines for porting C ++ code to MacOS?

For the upcoming project, it is planned to migrate existing code to C ++, which compiles on Windows and Linux on MacOS (leopard). Software is a command line application, but an external GUI can be scheduled. MacOS uses the g ++ compiler. Having the same compiler as Linux, it seems that no problems will arise, but there are always.

Are there any recommendations or problems that need to be observed during the port?

+4
source share
4 answers

Your application has a GUI, and which one (native / Qt / Gtk +)?

If not, then the problems that need to be observed (compared to Linux) are mainly related to the dynamic area of ​​communications. OS X uses "-dylib" and "-bundle" and actually has two types of dynamic libraries (loadable at run time and normal). Linux has only one look (-extended), and in any case it is weaker.

If your application has a graphical interface, you need to transcode all of this into Cocoa using Objective-C. This means that you will also become a new language. Some people (like MS) used Carbon (C ++ API), but it is gradually phasing out. I would not recommend this for new projects.

Best to use Qt or Gtk +. The Gtk + threshold was announced a few days ago (see Imendio ).

ps OS X, of course, launches the X11 binaries, but moving to any of your clients can be a daunting one. They are used to the Aqua interface and are productive with it. Consider X11 only a very short-term solution.

pps The number of additional open source libraries shipped with OS X is limited and may not be available. If on Linux you can easily require that users have “libxxx vyy” installed, OS X has several approaches to packaging (fink, macports), and for a commercial tool it is expected that the required libraries will be contained in the application. OS X offers “application packages” and “frameworks” for this (local copies, which makes the application self-sufficient). There is no such concept in Linux. It will also greatly affect your build system; maybe you want to try something like SCons for all platforms?

+8
source

You do not need to transcode everything in Objective-C. There's a weird bastardization of C ++ and Objective-C that will allow you to use C ++ code from Objective-C so that you can intelligently split the model code into C ++ and the view / controller code in Objective-C. To use Objective-C, simply suffix the source code files with .mm instead of .m, and you can mix most legal C ++ and Objective-C syntaxes even on the same line.

+1
source

We did not transfer to MacOS, but ported files from Linux to various Unix, the main work area was installation and startup systems, so we expect that there will be most of the work (if you already exist portable between Linux and Windows).

0
source

Macintosh (macosx) is essentially FreeBSD under the hood (although it has been modified). There are some differences in system programming between Linux and FreeBSD. First of all, these differences exist between different system calls ... so how much it affects you will be determined by what your application does and what type of system calls you make at runtime.

0
source

Source: https://habr.com/ru/post/1277269/


All Articles