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

15,967

Solution 1

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

Solution 2

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.

Solution 3

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:

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

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

Solution 4

(3 years later...)

If you have NON-EXPRESS, thus allowing the use of plugins, then there's stuff like WinGDB and VisualGDB to help you.

Duckduckgo also tells me about make-it-so which 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.

Share:
15,967

Related videos on Youtube

Toad
Author by

Toad

Updated on April 30, 2022

Comments

  • Toad
    Toad about 2 years

    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.

    • Admin
      Admin over 10 years
      An excellent question. I loathe Eclipse and GDB. Clunky, poor use of screen real-estate, one monitor, lousy printer support, etc... uuugh. Windows though just doesn't have the POSIX timer support I need for telco apps, and our production environment is all Linux, so I have been looking for a solution. I like the look of WinGDB and VisualGDB solutions MaHuJa pointed out below, so will investigate those. Any feedback you can offer after 3+ years?
  • David
    David almost 14 years
    We are using CMake to remove the dependency on the Visual Studio project system. Works nicely. cmake.org
  • Toad
    Toad almost 14 years
    Great tips. I'll make sure to regularly test and build on other platforms. I'm guessing that the initial setup will take the longest (configuring libs, makefiles, etc) but eventually things get simpeler down theline right ?
  • Toad
    Toad almost 14 years
    So when new files are added to the project i'll be doing that from cmake and then boot up visual studio?
  • rubenvb
    rubenvb almost 14 years
    Until you code a large portion of code and see that your assumption isn't correct on the other platform :). In theory, it should, if you get the build system right (with regards to the linker: .lib/.dll (.dll).a/.so andsoforth, paths, platform detection...)
  • Edward Strange
    Edward Strange almost 14 years
    @toad - more or less, yeah. VS hasn't been able to output makefiles since 2005 or earlier. Frankly, you're better off with something else if you want to do cross platform development. MS tends to discourage such things as much as possible and in VS they do so by making it pretty much impossible.
  • rubenvb
    rubenvb almost 14 years
    There are tons of them: QtCreator, Code::Blocks, Eclipse (CDT plugin), Netbeans (plugin). These are in order of personal preference.
  • Edward Strange
    Edward Strange almost 14 years
    I'm a fan of Eclipse, mainly because of the task based development model and the various other team tools offered by mylyn and tight integration with other plugins.
  • Toad
    Toad almost 14 years
    @noah I have some experience with eclipse (used it for flex, for php and for python). It's full featured, but always has a sluggish feel to it.
  • Toad
    Toad almost 14 years
    @rubenvb qtcreator looks really snazzy. Very nice with the qt support built in
  • rubenvb
    rubenvb almost 14 years
    @Toad: it also has git, svn, mercurial, cvs, CMake, and debugging support :). And it is pretty snazzy, yeah.
  • Admin
    Admin over 10 years
    I want to use Visual Studio to debug Linux C/C++ code, so this looks like the ticket. Thanks a million times over if it works as advertised. It will make my life so much easier.