Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

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?

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.

like image 707
Toad Avatar asked Aug 17 '10 18:08

Toad


People also ask

Is Visual Studio C++ cross-platform?

C/C++ support for Visual Studio Code is provided by a Microsoft C/C++ extension to enable cross-platform C and C++ development on Windows, Linux, and macOS.

Can Visual Studio be used for C?

Visual Studio Code is a lightweight, cross-platform development environment that runs on Windows, Mac, and Linux systems. The Microsoft C/C++ for Visual Studio Code extension supports IntelliSense, debugging, code formatting, auto-completion.

Is Visual Studio A good IDE for C?

Visual Studio is an excellent IDE for C++. If you know it from C#, it will be comfortably familiar. Show activity on this post. There is something to be said for starting to learn a language like C++ by not using an IDE at all, but by building from the command line.

Can we use Visual Studio for C and C++?

Install the components you need for building C and C++ appsWe also offer the ability to download software with Visual Studio.


2 Answers

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

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.

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

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).

like image 136
rubenvb Avatar answered Nov 03 '22 19:11

rubenvb


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.

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.

like image 38
Edward Strange Avatar answered Nov 03 '22 18:11

Edward Strange