开发者

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?


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.


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.


Use standard C++. Try not to use compiler dependant features like __int64 or platform specific external libraries and you should be fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜