简体   繁体   English

是在Visual Studio 2010中成功编译时可移植到Linux的c ++源代码

[英]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 ? 我应该在WindowsLinux上使用哪种编译器?

The compiler is unimportant as long as you use standard C++ and no platform specific extensions. 只要您使用标准 C ++并且没有特定于平台的扩展,编译器就不重要了。 If you need system specific facilities (networking, filesystem...), try to use an abstraction layer such as boost . 如果您需要特定于系统的设施(网络,文件系统......),请尝试使用抽象层,例如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. 正如其他人所指出的,最重要的是,您只使用标准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.

相关问题 当在Visual Studio 2010中编译`C`文件时,它是否编译为C ++文件? - When one compiles a `C` file in Visual Studio 2010, is it compiled as a C++ file? C++ 程序在 Visual Studio 2010 中编译但不在 Mingw 中编译 - C++ program compiles in Visual Studio 2010 but not Mingw Visual Studio 2010中是否有编译器设置可确保编写可移植的C ++? - Are there compiler settings in Visual Studio 2010 to ensure the writing of portable C++? Visual Studio 2010创建编译代码的应用程序 - Visual Studio 2010 Creating application that compiles code 在Dev C ++上编译相同的代码,但在Visual Studio 2017上编译 - Same code compiles on Dev C++ but not on Visual Studio 2017 C ++ Visual Studio编译器将本地代码编译为托管 - C++ Visual Studio Compiler compiles native code as managed C ++代码在CentOS g ++中编译,但在Visual Studio 2008中不编译 - C++ code compiles in CentOS g++, but not in Visual studio 2008 Visual Studio 2010 C ++代码格式化程序 - Visual Studio 2010 C++ code formatter 此代码编译但在Visual Studio 2015社区中运行(c ++)时不显示输出 - this code compiles but doesnt show output when it runs (c++) in visual studio 2015 community Visual Studio 2019 c++ 对概念的支持 - 编译成功,但出现错误:为什么? - Visual studio 2019 c++ support of concepts - compiles successfully with error: Why?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM