Visual Studio cross-compilation to Linux - c++

Visual Studio 2015 has brought with itself a cross-platform support for native C++ projects. In this context cross-platform means Windows, Android and iOS.
New Visual Studio now officially supports CLang and GCC tool-chains along with its own compiler. However it doesn't support cross-compilation to Linux.
Which, in turn, means that one still have to maintain at least two different projects in different IDEs to get native library binaries for all major operating systems.
Is this possible to "cheat" on Visual Studio and enable Linux targeting by modifying parameters of native Android project and/or by modifying NDK installation?
After all, Visual Studio just invokes NDK tools through a command line...

Before Windows 10 Anniversary Upgrade it was possible to cross-compile to Linux from within VS with Visual C++ for Linux Development extension.
However, you still had to setup a Linux machine (either real one or VM) since this extension supports Remote build & debugging only.
Windows 10 Anniversary Upgrade has introduced Windows Subsystem for Linux, which:
lets developers run Linux environments -- including most command-line
tools, utilities, and applications -- directly on Windows, unmodified,
without the overhead of a virtual machine
Thanks to this great feature happy owners of Windows 10 can easily setup remote cross-compilation to their localhost.
You can get the details either in official Microsoft blog post or here.

Related

Cross Platform c++ and Visual Studio 2017?

Is it possible to compile c++ project for Windows, Mac, Linux in Visual Studio 2017?
If not please give me a best way to compile for cross platforms.
No. It is not generally possible to do that with Visual Studio.
In my opinion, the best approach is to configure your CI system to spin up virtual machines running those other operating systems and then perform the build natively in the VM using whatever compiler those systems provide (like GCC & Clang). With the help of a build system like SCons or CMake you can abstract away most of the platform specific compiler bits.
A bonus is that building your code (and running your tests) with multiple compilers is a good way to find bugs.
Visual Studio 2017 added support for building and debugging for Linux, either on a remote machine or using some new built in local subsystem.
A fully cross-platform solution for you, porting your existing projects from VS could be as follows:
Start by converting your entire solution tree to a CMake project (VS 2017 fully supports loading such a project instead of the MS project format of the .sln and .vcxproj files). You can try a conversion tool like this one.
Now that you have a CMake project you can use the CMake build system directly from any other platform. For example on a Virtual Machine running your target OS. There, all you need is configuring your CMake project to build with clang/gcc instead of msvc.
If you prefer staying closer to home for now, in terms of editor/IDE that can be configured to build from the GUI -- kind of like the VS you're used to -- look for a cross-platform editor that supports CMake projects like VS Code.

Deploy a c++ game to other windows machines

I have created a c++ game with the following libraries : SDL2 and SDL2_MIXER. I want to give the game to some friends who have no programming experience to play with. Now I don't really know how to do that.
What I have tried is to use installshield limited edition with visual studio. After giving the installation program to some friends they all had a common problem-error that a dll MVCsomething was missing.
What is the simplest way to give my friends the app? Since c++ is translated to assembly do I have to compile the source again each time I change a machine?
Given the way that you've tagged your question, it is unclear if you are using Visual Studio or CodeBlocks to compile the code.
I guessing that you're compiling it in Visual Studio, and therefore they're getting an error that they don't have the appropriate MSVCRT DLLs—in other words, the C runtime library that your code depends upon, having been compiled with Microsoft's compiler. Point them to download the version of the Visual C++ Redistributable matching the version of Visual Studio that you're using on your development computer. For example, if you have VS 2015, they'll need to install Visual C++ Redistributable for Visual Studio 2015.
Alternatively, you can bundle the required redistributable into your installer to make sure that it gets installed automatically, if it isn't already. In InstallShield, I believe that's done by marking the VC++ Redistributable as a "requirement". Make sure that it's set as a prerequisite. Although, judging from the answer to this question, it may be that InstallShield LE doesn't support this. If that's the case, my advice would be to ditch InstallShield altogether and use something like Inno Setup to build an installer. There is a moderate learning curve, but it is useful knowledge. That being said, I can't believe Microsoft would ship a mechanism for creating a setup program with Visual Studio that didn't support automated installation of the CRT. I have not kept up with what Visual Studio supports nowadays with respect to setup wizards.
Since c++ is translated to assembly do I have to compile the source again each time I change a machine?
No, no. Assuming that your friends are all running Windows (and not, say, Linux) and have x86-based machines (which they do if they're running Windows), your code will work fine. The only hitch would be if you are compiling 64-bit code that runs on your machine, but they only have 32-bit machines. Then you'll need to have a 32-bit and 64-bit version. (Or a single 32-bit version, which will run on both.)

Which Visual Studio to target broadest array of Windows machines?

I develop a large open source C++ program. On Windows, we typically build our downloadable releases with Visual Studio Express. In the past, I've tried to use an old version of Windows and an old version of Visual Studio to try to maintain compatibility with as many user's machines as possible -- and to also keep the development environment as accessible as possible to contributors.
We do use some C++11. We currently use VS 2010 Express on Windows 7 Enterprise SP1 (64 bit). We target Win32. We do not use any .Net stuff.
Unfortunately, as built, our program crashes on Windows 8.1 -- it starts to load, but crashes with a non helpful error message 'myprogram.exe Has stopped working.' I can't yet tell if this 'should work', or if it is a bug in our program that only Win8 triggers (it works fine on earlier Windows as well as OSX and Linux).
I'm finding it very difficult to figure out the target compatibility matrix for Windows & Visual Studio. Assume that all versions of Windows and Visual Studio are available.
So, what version of Visual Studio and/or Windows SDK 'should work' to produce a single executable that will work on the widest range of Windows versions?
Or, what is the minimum number of builds (and how) we could do to target the widest array of Windows versions?
Alternatively, would MinGW provide a substantially better result for us? If so, which version & platform should we use?
We currently only build 32-bit versions, but how would going 64-bit change this discussion?

Can I deploy for Windows 2000 using Qt 4.8.4?

I have created an application using Qt 4.8.4, and now I have to distribute it on Windows 2000 machines, among the others. I have already tried searching over the Internet for a clear explanation about it, but I can't find a confirmation on what's the older Windows version actually supported by Qt.
The application runs fine on Windows XP (both 32 and 64 bit) and Windows 7 but, when I try to launch it on Windows 2000 I receive the well-known error "[Application name].exe is not a valid win32 application.", and I guess that the error relies on the unsupported Windows version.
The application is a "simple" one, it just need QtCore4.dll and QtGui4.dll as dependencies.
If it can help, I am developing on a Windows 7 64 bit machine, using Qt 4.8.4 and Qt Creator 2.7.1. If I go under Tools->Options->Build&Run->Kits->Manual->Desktop, I have "Microsoft Visual C++ Compiler 10.0 (x86)" as the compiler in use. Do I have to select a different one, maybe?
Thanks for any answer.
EDIT: What I've done after reading #vahancho's answer:
"Move" the project from Qt Creator to Visual Studio 2010, using CMake;
Install Visual Studio Express 2008 (enabling the V90 Platform Toolset, this way)
Open the project from VS2010, and go under Project Properties->Configuration Properties->General and change Platform Toolset to V90;
Recompile the project;
Now, I've tried to run the application compiled this way on a virtual machine, mounting Windows 2000, but I get another error, this time: "The procedure entry point DecodePointer could not be located in the dynamic link library KERNEL32.dll".
Well, after some investigations I found that running MSVC10 applications on Windows 2000 is not possible. You have to build it with at most MSVC9 (Visual Studio 2008), or use the VS2010 Multi Targetting feature to let VC++2010 use the VC++2008 compilers and libraries. Please also refer to this Microsoft Connect discussion.
OK, some time has passed, but I'd like to give a definitive answer to this question of mine. Unfortunately, what I was asking for it's not possible. #vahancho's answer is right, and the solution he pointed out is correct for the majority of situations. However, DecodePointer is "included" in Windows XP SP 2 kernel, and it's not possible to compile an application using it for an older Microsoft OS, even by choosing the VC++2008 compiler.
An additional reference is given by this post on CodeProject.
Fortunately for me, my application was simple enough to let me rewrite it using the good old VB6 :)

What development environment is required to target `C++ 2008 Redistributable`?

Last week I inherited a legacy unmanaged C++ application.
Unfortunately the project settings are not 100% reliable, and there is no documentation. What I do know is that the product was deployed with Microsoft Visual C++ 2008 Redistributable x86.
My question is: what combination of IDE, SDK, and Platform ToolSet would you recommend using?
Unfortunately I haven't worked with the Windows SDK before, and the Platform ToolSet option is new to me. To make matters worse, I haven't written a line of C++ code in eight years! So... any feedback you can provide would be greatly appreciated :D
KNOWNS
Client Operating System
Windows 2008 R2
C++ Redistributable
Microsoft Visual C++ 2008 Redistributable x86 is deployed in production
Integrated Development Environment (IDE)
I would prefer to use Visual Studio 2012 (we also have: Visual Studio 2008, 2010, 2012)
UNKNOWNS
Platform ToolSet
Can I use VS2012 and target the v90 platform, or is it more stable to simply use VS2008?
Windows SDK
Which version of the Windows SDK should I install on the development machine if the client is using Microsoft Visual C++ 2008 Redistributable x86 in production?
I would start by trying to get the project to compile successfully in Visual Studio 2008, since you mentioned you already have that available.
I wouldn't bother trying to install another version of the Windows SDK (one comes bundled with VS 2008) unless you can't get the project to compile successfully in an out-of-the-box install of VS 2008. If not and you do want to try installing another version of the SDK, I would opt for version 7.1, the one that targets Windows 7.
There is unlikely to be any advantage in using version 6.1 of the SDK; new versions might add new features, but they generally retain backwards compatibility with the old versions. I would not, however, install any version of the Windows 8 SDK because that might end up confusing you as the developer.
Once you get everything up and going on VS 2008, you could try switching over to VS 2012 if you'd prefer to use it. (I still can't get used to the UI, but apparently someone likes it.) As you point out in the question, the easiest way of making this work correctly would be to target "v90", which is VS 2008 (set using the Platform Toolset option). That will basically allow you to use the VS 2012 shell for editing purposes, but the VS 2008 compiler and headers for builds. You won't get any of the C++11 features introduced with VS 2012, however, because you're not using the new version of the compiler; you'll be stuck with what was supported back in VS 2008.