How to deploy a C++ code as a macOS application?

Hi! I am quite new at programming. I am at the stage where I can write code in C++ as a command line tool with Xcode. What I can't really see is how can I go one step further and translate this code into an application. Could somebody please enligth me about the steps from code to macOS app?


Let's say I have a hello world program which gets user input as a string, and display it. But instead of std::cin and std::cout in the Terminal, I would like make a very basic UI and make this code sharable to other Mac users. The code itself is in C++ but I quess the UI should be in Swift in case of a Mac app. How to connect to 2 different language?


Thank you in advance!

MacBook Pro

Posted on Aug 18, 2019 3:20 AM

Reply
5 replies

Aug 18, 2019 1:51 PM in response to Hordon13

There aren’t any keyword to search for. It is a very esoteric exercise. I think I’m one of the few people who have ever attempted it and I have only experimented. I think I posted a couple of how-to posts on the Apple Developer Forums (https://forums.developer.apple.com/welcome - I tried to find them but the search over there is pretty bad).


Often they write everything in HTML and just fake the UI. That is pretty easy to do on iOS. It is possible on the Mac, but much more difficult due to the styling of the UI. Again, I’ve done this as an experiment too. I wouldn’t say that C++ is a language to avoid. Rather, I would say attempting to support multiple platforms is something to avoid. Big companies like Microsoft can do it, but even then, it is clunky and it takes them a few decades to figure it out.


Focus on what you want to do with the app. What platforms are you targeting? For what reason? For example, if you are trying to make a mobile app to make money, forget about anything other than iOS. If you are trying to appeal to people in the OpenCV community, then forget iOS. It is a subtle topic.

Aug 18, 2019 10:37 AM in response to Keith Barkley

Thanks @Keith, the linked article was very useful, with this I could make a basic command-line swift app, using C++ code. My actual code what I would like to implement in Swift is consist of 60+ .h and .cpp, with 100+ different function and around 10k lines of code. I use other C++ libraries like OpenCV or SQLite3 as well. I case of something like this, the best practice is the same as mentioned in the article, or there are other ways?

Aug 18, 2019 12:11 PM in response to etresoft

Thank you very much @etresoft! Could you please provide me some keywords what I can search to learn more about this topic? Currently I am a bit unclear about the relations between Swift, Objective-C and Objective-C++. Actually I would like to learn more about how to connect different languages. I have read that lot of companies don't develop native apps nowdays, they work on a common code base instead and then make the UI and other high-level stuff in the target platforms language. How they manage this? C++ is a language to avoid when you would like to make applications to multiple platforms?


If you know some good articles in this topic I would really appreciate if you share it with me - I only find fragment of informations and it's a bit hard to me the see the big picture and the actual practices. Thanks again!

Aug 18, 2019 11:42 AM in response to Hordon13

Sorry, that isn’t practically possible, especially for a beginner. C++ is only suitable for low-level, back-end code. There is no user interface API for C++. All of that runs in Objective-C. You can fudge it a little bit with Objective-C++, but all of the UI and higher-level OS interfaces have to be pure Objective-C, no C++ allowed.


Swift is another wrapper around Objective-C, but the Swift wrapper is incompatible with the Objective-C++ layer. Technically it is possible to get C++ to work with Swift using either a C or Objective-C interface, but it’s not easy.


SQLite is just C, so that would be easy to use in Swift. OpenCV would be more of a challenge. You would probably have to wrap it in Objective-C.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to deploy a C++ code as a macOS application?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.