[英]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 我想使用Visual Studio 2010
来创建最终将在Linux上运行的C++ application
Are there any compatibility/version issues that I should be aware of? 我应该注意哪些兼容性/版本问题? Which compiler should I use on Windows
and on Linux
? 我应该在Windows
和Linux
上使用哪种编译器?
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. 正如其他人所指出的,最重要的是,您只使用标准C ++以及任何可移植到您所定位的所有平台的库。 But there are lots of other things to bite you too, eg 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. 但是还有很多其他东西要咬你,例如不同的行结尾(Windows使用\\ r \\ n,Unix变种通常使用\\ n),不同的数据类型大小等等。更常见的是当你试图保持便携性时,您还需要了解字节顺序,字节顺序,不同文件系统的工作方式等。
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. 我建议调查一个像CMake( http://www.cmake.org )这样的跨平台构建系统 - 它将为您节省一个痛苦的世界。 You don't want to have to be keeping makefiles for multiple platforms in step all the time if you can help it. 如果可以提供帮助,您不希望一直在为多个平台保留makefile。
Use standard C++. 使用标准C ++。 Try not to use compiler dependant features like __int64
or platform specific external libraries and you should be fine. 尽量不要使用编译器相关的功能,如__int64
或平台特定的外部库,你应该没问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.