[C++] Cross platform development

I'm planning to write a more or less simple application that just runs a Lua engine and some libraries like wxLua.
I want to use this as a base to be able to quickly write complete programs in Lua and have them working on Windows, Linux, OSX (and maybe even Android/iOS).

But since I've never really done anything on Linux/OSX, especially no development, I'm looking for an IDE that makes it easy to compile my project on multiple operating systems.
If for example I would use Visual C++ to create my project, I would likely have a very hard time importing and compiling it on Linux/OSX.

I'd really appreciate
-any general tips,
-suggestions or pros/cons for an IDE/compiler,
-advice on how to include complicated cross platform libraries like Lua in a suggested IDE/compiler (because it likely differs a lot from the way it works in Visual C++).

Thanks in advance and best regards
NopIt

Make (eg GNU Make) can automate building processes and works on Linux, OSX, and Windows (probably through Cygwin).
You can use whatever text editor you want. Netbeans also works on all platforms.

Code::Blocks or CLion are both cross-platform IDEs, although as @2bdkid suggested, make is going to do the building on each platform. Code::Blocks and CLion use make to build code just the same, the only difference is that they have a shiny GUI to help you out.

Your IDE should be arbitrary in the regard to building and running the code. It shouldn't matter which system (Windows, Linux, OS X) you develop your code on since it should compile and run just fine on the other systems if it is cross-platform code. Personally, I would stick with the IDE I feel most comfortable with, so if Visual C++ is your preference, then stick with it.

I think what you might be hung up on is you don't have the nice "Run" button when you go to the other systems as you might have with your primary IDE or that you'll have to do exhaustive re-testing on all three systems each time you have a new build. For that, I recommend you look into something like jenkis where it will compile using make and run you're test suite every time you push new code to the repository.

The problem I see with that, is that in Visual C++, you do a lot through the GUI. Like setting the include directories, library directories and lib dependencies... This code is probably saved in a .sln or .vcxproj file, which are probably no standard that other compilers would understand.

Or am I wrong with something here?

The sln holds project settings and stuff. All your cpp and h files are there too.

yeah, its pretty much VC++ version of the makefile. If you're gonna be cross platform with C++, then you're pretty much gonna have to create a makefile. You can still use VC++ IDE, but you'll have to maintain the makefile outside the project.

I vaguely recall generating makefiles in VC++, but it seems to have been taken out. http://stackoverflow.com/questions/2839221/how-do-i-create-a-makefile-from-a-visual-studio-solution-file

In that case, maintaining a separate makefile will be a burden. Give CLion a try. I've been playing with CLion, it's been fun and has the JetBrains flair for a great IDE even though it is only in early access.

Why did you choose C++ over something like C# Mono or another language?

I will.

Isn't C# Windows only?
Well, I choose C++ because I know it, because I think it is very efficient and because I can use classes in it, which might come in handy some day.
I also thought about Java, but I don't like the fact, that my program could only run if the user has additional software installed.

I like using Code::Blocks and Netbeans, however I do like Netbeans a little more as do a lot of my professors. But you can't really go wrong with either.

You can use C# on Linux maybe on even more platforms, with the mentioned Mono. I have tried running production code on it and was not too surprised when building that dependencies were a headache and as I had time constraints, my experience with it was short and bitter. If you make sure that you can build your code with Mono all through, you should have no trouble.
Oh and another thing, you can precompile Java to native code, there is an option, though I don't know what is it as I never use it.

Yep. C# Mono .Yeah, @DevBlox is right and thats where we come back to building and testing frequently with using a continuous integration tool like Jenkins. You're going to want to do that step no matter what language you are building in. If your project is open source, you can use something like Travis CI for free, although I believe it will only build on Linux and OS X.

I've heard many people refer to C++ as "write once, build everywhere" and Java "compile once, test everywhere" even though the Java fanboys like to say "write once, run everywhere."

I'm not understanding. Most languages have classes. Are you saying you want to be able to reuse your code in other projects?

C# Mono is going to require the mono framework to be installed to run. I don't see that be that terrible of a compromise, but it is up to you.

1 Like

In my opinion the question should be:
Why not C++?
There are lots of libraries and tutorials for it, the performance is super good, it runs on all OSs that I know of and it is a language that I have already used.

Having to install additional frameworks sucks because
-they use up a lot of disk space that C++ simply wouldn't need
-requires the user to find, download and install the framework
-is very expensive for companies who have to review and test the system stability of any software they have to install
-the program might stop working just because a newer version of the framework was installed
the best example would be Java (7/8)

and I'm sure there are more downsides that I haven't even thought about yet.

For the desktop clients , I see no wrong with C#, Java or C++. Though there is one question that I want to nail down here, are you building a UI or is this just a console app of some sort? If so , what cross platform UI framework are you intending to use? GTK? QT?

Another question is, how much do you want it to work on mobile? On Android you are Going to have to deal with the NDK ,and on IOS you are going to have to wrap it all up in an Objective-C app. These again bring up the UI question as these platforms have their own UI frameworks and as far as I'm aware there is no getting around that besides solutions like PhoneGap, Xamarin Forms and Titanium, though none of those are really C++ friendly

Well, for now I don't need classes, so I could do it all in C, I guess.
By default, it won't have a GUI. It will simply run a Lua engine with some Lua libs. One of them being wxLua which provides GUI functionality.
I'm most interested in this: http://docs.wxwidgets.org/trunk/classwx_web_view.html
Which would allow me to create my GUI with HTML code. But I'm not sure if that is Android/IOS compatible.

It looks like Visual C++ actually does support make files, but I don't really understand what VC++ is expecting form me: http://i.snag.gy/537AV.jpg
I guess I need some external command-line compiler/linker? But which one would be a good idea? And what would the command-line commands for it be?

That wizard doesn't look much more than a form in which you fill out and copies into the makefile. You're probably better off learning how makefiles work in general. I suspect the Visual C++ makefile generator will serve you better then.

Take a look at: http://www.cs.umd.edu/class/fall2002/cmsc214/Tutorial/makefile.html
and:

Code Blocks, as many have suggested, prides itself on being multi-platform.

Makefiles form Visual C++ (MS nmake) seem to be different from the unix compatible makefiles (Bell Labs nmake). So.. I will go with Code::Blocks, as it was really simple to set up.
Now the question is, what kind of project do I need to create?

Do I just create an empty project? Or do I need to create a wxWidgets project because I want to embed Lua with wxLua? But I kinda want a console of some sort, so that I can see the errors that Lua might throw, on the other hand I don't want a console, once the program is ready for release.

FYI you done need to make the make file yourself and for bigger projects its probably not a great idea. Cmake will build make files for you as well as any other make/project scripts for other OS' and IDEs like code blocks or vs though its another thing you need to learn.

How else are you meant to figure it out except for trying?

CMake will save your life. It can generate projects for all major platforms.

I might be too late to this but a "Console application" is a good starting point for most things really. The others are just smarter wrappers around it.