如何设置visual studio的跨平台c ++开发 [英] How to setup visual studio for cross platform c++ development

查看:332
本文介绍了如何设置visual studio的跨平台c ++开发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我不想放弃visual studio,我的希望是,可以使用visual studio和windows目标作为测试工具,然后每隔一段时间通过vm测试代码在linux或mac上。

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.

有没有人有如何最好地设置这方面的经验?

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

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

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.

推荐答案

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

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

之后,调高警告级别( / W3 应该这样做),并且非常小心你所做/写的。 IMHO,GCC更好地保持你的标准( -Wall -Wextra -pedantic -std = c ++ 11 ),但你指定MSVC。

After that, turn up the warning level (/W3 should 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.

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

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

记住使用平台/架构/编译器独立类型,例如 std :: size_t std::( u )intptr_t 等,而不是简单 int long

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

请参阅

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

这篇关于如何设置visual studio的跨平台c ++开发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆