Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting started with a cross platform C++ project

I am starting a c++ project which I would like to compile equally well in Eclipse (Linux) and vs2010 from the same repository and could use some help getting started. While many of the aspects can individually be Google'd, I was hoping for advice on how to approach the problem on a whole.

For example, where to keep the library sources, how to structure the make file, and how to integrate googletest (finding a novice tutorial on googletest alone is hard). A link to a tutorial that addresses these aspects would be great, or a series of tutorials that together could help.

My background is in C# and I'm trying to maintain the "cleanness" and organization of my VS projects.

like image 700
ccook Avatar asked Sep 24 '10 15:09

ccook


People also ask

Is C and C++ cross compatible?

Any C compiler that is compatible with the Oracle Developer Studio C compiler is also compatible with the Oracle Developer Studio C++ compiler. The C runtime library used by your C compiler must also be compatible with the C++ compiler.

How do you make a program cross-platform?

Implementation. For software to be considered cross-platform, it must function on more than one computer architecture or OS. Developing such software can be a time-consuming task because different OSs have different application programming interfaces (API). For example, Linux uses a different API from Windows.

Can I code C on Visual Studio?

The Microsoft C/C++ for Visual Studio Code extension supports IntelliSense, debugging, code formatting, auto-completion. Visual Studio for Mac doesn't support Microsoft C++, but does support . NET languages and cross-platform development.

Is C# good for cross-platform?

NET, as it is tightly connected with C#. With the acquisition of Xamarin and its native Mono Runtime in 2016, . NET and C# got cross-platform capabilities for the first time. Because of this, C# applications can be coded once and launched on any platform, including Web apps, Windows, macOS, Linux, Android, and iOS.


1 Answers

I have done cross platform projects that used the "native" build systems on both platforms (vsproj files on windows and makefiles on linux), but it was definitely a pain to maintain both project files. So, yes, I would agree with the other suggestions that you should try to start with a solid cross platform build utility. CMake or possibly Boost build seem like decent options - likely there are many others.

When it comes to 3rd party libraries, you'll want to stick to stuff that is solidly tested cross platform. Boost is the best general purpose library for c++ (yes, you see it mentioned here in just about every c++ thread...but that's because it really is a nice collection of useful stuff). As for XML, HTTP, image libs, UI - there are all good cross platform options - just look around or ask here if you have specific requirements. Whatever you do, don't use some library from CodeProject or other MS oriented site that has only been tested with Visual Studio 6 - that will just lead to misery. Most of the GNU libs build on windows these days, so you should be reasonably safe with that stuff.

Although it will be tempting, try to minimize the platform#ifdefs in your code - prefer instead to abstract any platform specific stuff in a library wherever possible.

Good luck!

like image 124
Mike Ellery Avatar answered Sep 20 '22 13:09

Mike Ellery