windows 如何为跨平台 C++ 开发设置 Visual Studio

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3505639/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:03:18  来源:igfitidea点击:

How to setup visual studio for cross platform c++ development

c++windowsvisual-studiounixcross-platform

提问by Toad

After some time mainly .net development, i need to work in c++ in a cross platform manner.

经过一段时间主要是 .net 开发,我需要以跨平台的方式在 c++ 中工作。

I don't want to give up visual studio, so my hope was that it is possible to use visual studio and the windows target as a testbuild, and then every once in a while through means of a vm test the code on linux or mac.

我不想放弃visual studio,所以我希望可以使用visual studio和windows target作为testbuild,然后每隔一段时间通过vm在linux或mac上测试代码.

Does anyone have experience in how to best set this up?

有没有人有如何最好地设置它的经验?

I'm especially curious on how you make sure that things like the project file stay in sync with the make files which are probably needed on the *nix platforms.

我特别好奇您如何确保项目文件等内容与 *nix 平台上可能需要的 make 文件保持同步。

采纳答案by rubenvb

First of all, select a non-managed C++ project (to avoid the .net stuff).

首先,选择一个非托管的 C++ 项目(以避免 .net 的东西)。

After that, turn up the warning level (/W3should do), and be very careful what you do/write. IMHO, GCC is better at keeping you straight with the standard (-Wall -Wextra -pedantic -std=c++11), but you specify MSVC.

之后,调高警告级别(/W3应该这样做),并且要非常小心你所做的/写的。恕我直言,GCC 更擅长让您直接使用标准 ( -Wall -Wextra -pedantic -std=c++11),但您指定了 MSVC。

As Noah said, you'll need build system that is in itself cross-platform, like CMake (there are others, please don't forget that).

正如诺亚所说,你需要一个本身跨平台的构建系统,比如 CMake(还有其他的,请不要忘记)。

Remember to use platform/architecture/compiler independent types, like std::size_t, std::(u)intptr_tetc. instead of plain int, long, unsigned: these are a recipe for disaster and the Windows API throws these around way too much.

请记住使用平台/体系结构/编译器独立类型,例如std::size_t,std::(u)intptr_t等,而不是普通的int, long, unsigned:这些是灾难的秘诀,Windows API 将它们抛得太多。

See here, but only/especially points 1, 2, 5, and 8 (and 9, but generalize that to svn, git, mercurial).

请参阅此处,但仅/尤其是第 1、2、5 和 8 点(和第 9 点,但将其概括为 svn、git、mercurial)。

回答by Edward Strange

I'm especially curious on how you make sure that things like the project file stay in sync with the make files which are probably needed on the *nix platforms.

我特别好奇您如何确保项目文件等内容与 *nix 平台上可能需要的 make 文件保持同步。

Since MS decided to remove support for makefiles from VS, you don't. You use something else that can generate VS project files and make sure you keep THAT set up correctly. Something like CMake.

由于 MS 决定从 VS 中删除对 makefile 的支持,因此您不需要。您使用其他可以生成 VS 项目文件的东西,并确保正确设置。像 CMake 的东西。

回答by MaHuJa

(3 years later...)

(三年后……)

If you have NON-EXPRESS, thus allowing the use of plugins, then there's stuff like WinGDBand VisualGDBto help you.

如果您有NON-EXPRESS,从而允许使用插件,那么WinGDBVisualGDB之类的东西可以帮助您。

Duckduckgo also tells me about make-it-sowhich is rather out of date - but there may be yet more of those by now, since they should be simpler to make with the new xml based project formats.

Duckduckgo 还告诉我有关make-it-so 的内容,它已经过时了 - 但现在可能还有更多,因为使用基于 xml 的新项目格式制作它们应该更简单。

回答by justanotherxl

This is an ancient question from 6 years ago, but I'd just like to point out that Microsoft now has official tools to work with linux c++ in Visual Studio:

这是 6 年前的一个古老问题,但我想指出的是,Microsoft 现在拥有在 Visual Studio 中使用 linux c++ 的官方工具:

https://blogs.msdn.microsoft.com/vcblog/2016/03/30/visual-c-for-linux-development/

https://blogs.msdn.microsoft.com/vcblog/2016/03/30/visual-c-for-linux-development/

In addition, Windows 10 now has abilities to run Linux insideWindows, so it should make your life a lot easier for anyone still interested in developing in C++ for Linux on Visual Studio.

此外,Windows 10 现在能够Windows 中运行 Linux ,因此对于仍然有兴趣在 Visual Studio 上为 Linux 开发 C++ 的任何人来说,它应该会让您的生活变得更加轻松。