GUI in C++ for OS X Mountain Lion - c++

I need to be able to launch a basic GUI from an application written in C++ on Mountain Lion. The obvious ways this would normally be accomplished is through either a cross-platform library like gtk or qt or by launching the c++ code from an objective-c based application. Each has its problem in this case. The application I'm writing uses a class library to connect to a robot. For the application to use the functionality, it must be compiled using the g++ compiler from terminal. The code was never designed to run on anything past Snow Leopard, so it's quite touchy when it comes to compiling and linking. This would seem to preclude my ability to start the C++ code from objective-c written using the xcode ide unless xcode includes compile options that I'm not aware of, at which point other platforms like gtk or qt seem viable. The problem with those is that I haven't been able to get a single one to even compile on Mountain Lion, let along been able to write an application using one. Is this a problem with Mountain Lion/lack of updates? And are there other options for creating the GUI? Maybe a GUI library compatible with Mountain Lion or a way to launch a cocoa-based GUI from the C++ code? It doesn't need to be complex - just a window with some lines drawn in it.
Thanks in advance!

Related

Do I have to be on a specific OS to compile for a specific OS when using Qt?

When I was using pyqt it was necessary to compile for mac on a mac, instead of being able to export a build for mac from linux (or windows, or whatever)
Now that I'm using straight c++ development, does this fact change at all? Or must I still compile for a given OS on the given OS?
Ideally I'd love to be able to just pick a platform and compile for it. Unity3d does this, but I imagine I'm comparing apples and oranges at this point.
Is this possible? Or do I got to find a friend with a mac? Cuz I don't have no friends... ;)
Typically yes, you have to. In some cases you can cross-compile, for example, this is available stock for android apps, as there is no Qt SDK that can run on android cross-compilation is the only option. You can also build a custom Qt to cross-compile to another OS. This is not available by default, it requires a custom build.
However, when it comes to ios or macos cross-compilation is not an option, as far as I know there is no way around but to compile under macos.

Can a C++ program run on Mac OS?

I have watched a video in which one of the director of scs software (who makes a EURO TRUCK SIMULATOR game) saying that the game is written entirely in C++, yet the game runs on Windows and Mac OS as well. How could they achieve it? Is it possible to run a C++ program on MAC OS?
Yes.
...OK, stack overflow wants at least 30 characters. OS X comes with the C++ compiler clang++, which is built on top of llvm. In fact, Apple stopped supplying a port of gcc some time ago, so developers either have to build it themselves or adapt to clang. According to Wikipedia, Apple itself develops clang.
It is possible, either to run gcc in terminal or to use Xcode to compile it, however you cannot then use Cocoa but alternatives such as Qt are available for mac.
Sure, there are C++ compilers for Mac OS X as well. One is even included in xcode (the standard development environment on a Mac).
But that does not mean, that you can compile just any C++ program on a Mac. It has to be designed to use libraries, that are available on both platforms (instead of MFC on Windows or Cocoa on the Mac). This is possible for example by using wxwidgets or QT. With these two libraries it is even possible to compile the program for Unix platforms like Linux as well.
Regardless of language a multi-platform program relies on some basic support parts that are implemented differently on each platform. With pure standard C++ this is the standard library and the runtime support, but in practice a game, say, will also rely on 3rd party libraries with platform specific implementations. So given that the platform itself is compatible with the basic platform assumptions of the C++ language, and the Mac is, achieving such portability is conceptually very straightforward, although difficult to get perfect.
As an example of a platform that's not entirely compatible with C++, Microsoft's .NET virtual machine is apparently so at odds with the ideas of C++ that Microsoft has found it necessary to define two different non-standard variants of C++ for it, and offers no way to produce GUI programs for it in pure standard C++. It's not impossible to use only standard C++ for .NET, and indeed one main reason to use C++ with .NET is to combine standard C++ parts with more .NET-y parts; it's just that using only standard C++ the code becomes complex, inefficient and generally impractical. For example, my first questions here on SO concerned how to do a simple .NET message box in standard C++ by way of COM technology as an intermediate layer, and that worked, but with a ridiculous amount of complex non-general support code.
As another example, using C++ in web pages is very much an impedance mismatch, so to speak. Again Microsoft is the main player who has attempted this, with their ActiveX technology. It turned out to be a good way ensure that PCs all over the world got infested with malware, because C++ is not the kind of language where it's easy to constrain what the code can do. As far as I know only Microsoft's own Internet Explorer browser ever supported ActiveX in web pages. And as of Windows 10 the IE browser is being phased out and replaced by the newer Edge browser, that does not support ActiveX in web pages.

Programming in C++ with Xcode 4

I want to use Xcode as my major complier for C++. However, I'm having a hard time starting programming. Which kind of project and target should I select if I want to write some applications with user interface?
I've been coding with Xcode for one semester but all the projects were half-done the time I saw them, so I really don't know how to start by myself. I tried the Command Line target but it did not seem to generate an application.
Sorry for asking these naive questions. Thanks for any help!
You can start with a barebones project by going to New -> New Project -> Application (under Mac OS X) -> Command Line Tool. This will give you a basic main() function that you can enter code into. This is what I use alot of the time for algorithm practice.
If you want your app to use a GUI framework, you can either choose the template that #sblom suggested and make a Cocoa Application (here is a good guide to get you started), or you could use a C++ framework such as wxWidgets or Qt (usually used with it's own IDE, Qt Creator).
Note that while Cocoa is in Objective C, you could just as well program in C++ for the core functionality of your app, just make sure the implementation files have a .mm suffix.
You'll need to use Mac OS X -> Application -> Cocoa Application. Unfortunately, it won't exactly be in plain ol' C++, although you can use C++. You'll have to use Objective-C to make actual calls into the Cocoa Framework (well, there are ways to make the calls using straight C/C++, but that's really cumbersome.)
I will highly recommend to use QT but not WX.
We use WX for years in our Valentina Studio application. And we going switch to QT asap. Reasons are that WX on MAC has weak progress. Troubles with Cocoa support. QT looks much more better choice ...

Can a single eclipse C++ project link different libraries differently for different platforms?

I have a C++ eclipse project that I would like to easily compile In Windows and OSX.
The project is currently using an automatically generated makefile.
The libraries that I need vary depending on the platform.
In osx I'm using the CoreMidi, CoreAudio, and CoreFoundation frameworks.
In Windows I'm using the winmm.lib and multithreaded libraries.
What's the simplest way to link different libraries/frameworks depending on the current platform?
I'm currently using the gcc toolchain on OSX. Should I start using the cross compile toolchain?
Should I have two projects. One for working in windows, and one for osx, checking them both in to version control?
Should I write a custom makefile instead of using the automatically generated option that has different g++ arguments depending on the platform?
I personally had the same goal for a project and came to the conclusion the Qt framework was the best thing for me. It handles multiple languages, unicode strings, XML, network communications, native looking user interfaces, console applications: it can do an AWFUL lot.
However, as Paul pointed out, you really have to plan it from the start.
Qt does a good job of abstracting the platform away (in a module called QtCore) allowing you to write vanilla C++ code, or you can chose to include some Qt C++ language extensions which a Qt helper application called the moc (meta object compiler) creates vanilla C++ from, which can then be compiled by most common C++ compilers.
It also has a nifty cross-platform makefile generator called qmake which works on project files to create normal make files for the platform its running on.
Off the top of my head at least Windows XP & 7, OSX 10.4, 10.5, 10.6 are supported currently. But note that OSX Lion is (as of writing) not officially supported but I suspect it will be in the next release.
Based on your description, I am not sure you can easily make it cross-platform. Even without using third-party library, you have to provide separate code for osx and windows. Most of time, they design the system as cross-platform first. It's really hard to make an existing project on single-platform to cross-one. If you have the cross-platform requirement, you'd better design in that way first and rewrite from scratch.
Even though Eclipse can run fine on both OS X and Windows, it is not designed to be used in this way.
The best way to do it is to use separate IDE projects for each platform. This this is the easiest way to have unique compilation settings for multiple platforms.
Yes, you can use two eclipse projects. Alternatively, it's not unusual to have a X-Code project for OSX, and a Visual Studio Project for MS Windows.

GUI Programming C++ for Mac OS X Lion

I'm probably going to get abuse for this question but here goes. Oh but before you tear into me and tell to crawl back under a rock etc. I have looked high and low and nothing has helped me so far either the software libs are out of date and for some reason wont work on lion.
Ok other than Qt is there any other lightweight opensource GUI library for C++ on mac? I have tried this wxWidgets doesn't work for some reason. Apple don't seem to offer that carbon crap anymore or can I use openGL to create GUI's? I just want a simple nicely documented GUI lib without having to switch to windows to develop. or will I have to spend some money on one or resort to Qt.
Hope someone can help and thanks!
Why not use Cocoa (the native way to develop OSX GUIs) in the first place? You must use the Objective-C calls to create windows for example, but you can mix this code with C++ code in the same file - this is then called Objective-C++ and it is supported by clang and the gcc.
To build completely native-looking OSX Applications, you need Cocoa. Every other toolkit that can create those native GUIs calls Cocoa (at least to my knowledge).
Just as a pointer: have you tried SDL?
FLTK is simple and very stable GUI library. Runs on Windows, OS X and Linux.
Non-native look though.
Here is a screenshot of an app I built with it a few years ago, and that still runs great on Lion.
I'd take a look at both GLUT and GLUI as simple extensions to OpenGL that provide basic widgets. They can be used together to some degree, but I personally have run into a couple issues in that department. Either one in isolation is pretty simple to use if you're familiar with OpenGL though.
EDIT: Also, X11 can run in OS X, although I'm not familiar enough with the system to know how to get started with that.