Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is c++ source code portable to linux when it successfully compiles within Visual Studio 2010

I would like to use Visual Studio 2010 to create a C++ application that will eventually run on Linux

Are there any compatibility/version issues that I should be aware of? Which compiler should I use on Windows and on Linux?

like image 549
Dimitris Baltas Avatar asked Dec 13 '22 17:12

Dimitris Baltas


2 Answers

The compiler is unimportant as long as you use standard C++ and no platform specific extensions. If you need system specific facilities (networking, filesystem...), try to use an abstraction layer such as boost.

like image 132
icecrime Avatar answered Dec 21 '22 23:12

icecrime


There are lots of issues of which you need to be aware, unfortunately. The most important, as other people have pointed out, is that you use only standard C++ plus any libraries that are portable to all the platforms you're targeting. But there are lots of other things to bite you too, e.g. different line endings (Windows uses \r\n, Unix variants generally use \n), different data type sizes, etc. More generally when you're trying to keep things portable, you also need to be aware of things like endianness, byte-ordering, the way the different filesystems work, etc.

Essentially, the most important thing is to be familiar with all the systems you're targeting. Don't write it on one system and then expect to be able to compile it pain-free on another one. Instead, compile it on all the relevant systems from day one and make sure that it continues to work on all of them, all the time. I recommend looking into a cross-platform build system like CMake (http://www.cmake.org) -- it will save you a world of pain in my experience. You don't want to have to be keeping makefiles for multiple platforms in step all the time if you can help it.

like image 32
Stuart Golodetz Avatar answered Dec 22 '22 00:12

Stuart Golodetz