Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Learning and cross-platform development (C++)

I am writing a small C++ program for fun and for extending my C++ skill. Since its scope is relatively small, I also planning to try out cross-platform development by making this program support both Windows and Linux.

I reckon my C++ proficiency is sitting somewhere between casual and intermediate level: OO, a bit of templates and design patterns, used STL before and trying to look into it more in details, ... However, while coding this little program, I find that the deeper I dig into C++, the more pain I feel, especially when I come to understanding and dealing with differences between different platform's/vendor's implementation.

The use of cross-platform frameworks like Qt, ACE, Boost seems help to speed up development a lot thus make life easier, but I worry if this will beat my purpose. Can somebody give some advice if there is any "best practice" for doing C++ cross-platform development? Thanks.

like image 955
shiouming Avatar asked Oct 13 '09 04:10

shiouming


People also ask

What is the cross-platform development?

Cross-platform mobile development is the creation of software applications that are compatible with multiple mobile operating systems. Originally, the complexity of developing mobile apps was compounded by the difficulty of building out a backend that worked across multiple platforms.

Is C C++ cross-platform?

C++ is cross-platform. You can use it to build applications that will run on many different operating systems.

What is cross-platform in C#?

Cross-platform itself means to be able to do everything that you can do one platform, on another one too. C# is able to do the same, on every platform.


4 Answers

Can somebody give some advice if there is any "best practice" for doing C++ cross-platform development?

There are three things:

  1. Write your own code so that it's portable

  2. Wrap platform-specific APIs behind an abstraction/insulation/utility layer

  3. Choose cross-platform libraries

You can choose option #2 and/or #3.

Advantages of #3 over #2 tend to be things like, "It's already written, debugged, and supported"; and the disadvantages are like, "I have to learn it, I might have to pay for it, I can't necessarily support it myself, and it may not do exactly what I want."

Developers will often prefer option #3 instead of #2, especially if it's free open source (which all three of the libraries that you cited are).

like image 117
ChrisW Avatar answered Oct 05 '22 09:10

ChrisW


http://blog.backblaze.com/2008/12/15/10-rules-for-how-to-write-cross-platform-code/

Should provide more detail to the answers already given.

Also I suggest using existing libraries that abstract endianness, data type sizes and differences. The following should be considered before starting your cross-platform project.

GUI

  1. Qt
  2. XVT
  3. wxWidgets

General Libraries/frameworks

  1. STL (Incorporated in most platform libraries already)
  2. Boost

Game Development

  1. SDL
  2. Cocos2d-x
like image 44
Eat at Joes Avatar answered Oct 05 '22 08:10

Eat at Joes


Use gcc. It's available on both Windows and Linux and the libraries and language syntax is identical on both platforms.

For cross platform GUI applications, Qt is a good idea. There is no getting away from having a dependency on a GUI framework if you are trying to achieve platform independence.

like image 25
Phillip Ngan Avatar answered Oct 05 '22 09:10

Phillip Ngan


Unless you are doing GUI stuff cross platform isn't a big problem.

There are some small issues to do with filesystems ( different / \ separators, allowed characters in filenames etc) but these are at the application level rather than the c++.

Doing major applications gets more complex, you need to handle help, file locations an possibly security and user info in a cross platform way. For simple algorithm type programming there isn't a problem.

Qt is mainly a GUI library, although it has extra cross platform filesystems stuff. STL, Boost, ACE are cross platform but that isn't there main point.

like image 29
Martin Beckett Avatar answered Oct 05 '22 08:10

Martin Beckett