Visual studio 2010 project for windows and linux - c++

I'm trying to make a program that works on linux and windows.
I'm writing the program in visual studio in a windows environment.
So I wonder how I could compile my project from visual studio to linux.

The Microsoft C++ compiler is not capable of producing Linux executables.
You will need to use a more portable compiler for your Linux executables, e.g. gcc. Perhaps you may benefit from a cross-platform IDE like Code Blocks or Eclipse rather than Visual Studio.

You should try QT. It is pretty good framework for cross-platform development. The opensource version is free and very well maintained and has the LGPL license. That means you can sell your product as closed source but then you have to dynamically link to QT libraries.

You can use CMake. It will allow you to generate project/solution files for Visual Studio and Makefiles for Linux. This way, you can work using the native tool chain for a platform, while managing a single makefile. However, it's up to you to write portable code and to choose the appropriate libraries for your program to be truly portable.

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.

visual studio 2017 linux c++ librt

I've read, I can use Visual Studio 2017 on Windows to develop C++ application with remotely debugging on a Linux machine. I like this idea because I'm familiair with VS2017 for C# on Windows applications.
For my new study, I need to develop on Linux but for example must develope applications which use shared memory via Posix. So I need to include the LIBRT library. But this one is specific for Linux, so if I need to use such kind of specific linux library's, could I then also use this VS2017 setup?
If how, how does that work because I did not find any information about it.
Thx
I encountered the same obstacle but for libcurl. What fixed it was adding gcc arguments in the Visual Studio linker. Right click the project and pick Properties->Linker->All Optptions->Additional Options and add the same parameter you would give to g++, in my case -lcurl. I have also tested it for -pthread.

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

Is it possible to use vs2010 c++ and use Qt for all platforms?

What i hear about Qt, is that it is providing an operating system independent layer.
To do well most tasks a coder normally does. To perform at best the code has to be c++
While there is also mono providing some translation to c++ and there Dot24 an android c# kernel.
Currently the things we do, cannt be done in mono, for hardware reasons.
So i am thinking of going back to pure C++ and QT instead of C#.
Now what i am wondered about
By itself c++ is a standard and should also be idenpendent for linux/windows/unix/microboards/Ce devices etc etc.
But if i would write using VS2010 c++ and QT would i still have advantage my code would run on a wide range of platforms ? . As visual studio, creates a windows based exe? Or should i use also another IDE to write truely independent c++ with Qt?
C++ is a compiled language, whatever IDE/compiler you'll use it will produce executables for a certain platform. But the point of Qt is that, as far as you avoid platform-specific code, your sources can be recompiled on the various platforms, generating a different executable for each supported platform. So, using VC++ is not a limitation as far as sources are concerned.
The limitation comes instead from the build system: Visual C++ uses its own format for project files, which is not compatible with makefiles & co. So, if you started your project as a VC++ project, you would have to re-create manually a Makefile or similar to compile on other platforms.
To avoid this kind of problems, Qt provides qmake, a tool that, provided a .pro file (roughly equivalent to a .vcproj), is able to generate build files for various platforms: .vcproj/.dsp on Windows, Makefile on Linux and OS X, XCode projects on OS X and probably others.
So the point is: you can use Visual Studio, but you should use Qt's build system to be able to port your application to other platforms without any fuss.
Also, you can consider using Qt Creator, which supports directly .pro files, has particularly good integration with the Qt features and works on Windows, Linux and OS X; on the downside, I noticed that the debugger in Visual Studio tends to be way better.
If you have cross-platform C++ code using Qt, you can edit and compile the Windows version using Visual C++ (the compiler that comes in Visual Studio).
Visual C++ still only creates Windows executables, though, so to actually build and run on other platforms, you'll have to get another compiler (but feed in the same source code).
One pain point will be with makefiles: visual Studio has its own project format and cannot process standard makefiles. Neither do other platforms use Visual Studio projects. Visual Studio does come with a tool called nmake which is similar to POSIX or GNU make, but still not compatible except for the most trivial features. And of course cl.exe uses different command-line switches than other compilers. So you'll end up maintaining one set of C++ files but two or more sets of makefiles.
Yes it is possible to develop Qt applications in Visual Studio that can be used on other platforms. For example for my work in medical imaging research, I develop all of my Qt based applications in Visual Studio 2010 with the visual studio project files generated using CMake and at times build some of these applications in linux under QtCreator or KDevelop using the same CMakeLists.txt to generate project files for for these IDEs. As long as I stay away from platform specific code the porting is not that difficult.
In order to develop qt apps qtcreator is the best ide, qtcreator available on linux and mac, so you can open your qt project and build on any platform easily.

Simultaneus development in Visual Studio and a Linux IDE

I am trying to get started with an existing open source project (QuantLib) using Linux operating system. However it seems that most developers use Visual Studio (judging from the project files committed with the source).
Which Linux C++ IDE would be most compatible with VS project files? Is there a way to import/export them, so that I don't have to create my own projects from scratch (and update them every time someone adds a new file)?
EDIT: Its all unmanaged code
In my experience, the best method for doing dual-development on Linux & Windows is to throw away the existing Visual Studio project files and, instead, use CMake to generate the platform-specific build environment. It's capable of outputting Nmake makefiles (for command-line Windows builds), Visual Studio projects, and Linux makefiles. The documentation leaves a bit to be desired but once you have it up and running, it's very easy to maintain.
The FAQ provides installation instructions for MinGW. It seems that there is a GNU Makefile included, so you don't need to mess with Visual Studio project files.
Aparantly they they only build on MAC and Windows.
Instructions here: http://quantlib.org/install/macosx.shtml
But since MAC is basically BSD Unix it should be identical (or with little trouble) to get it up and running on Linux.
The following should work (though you may need to look at the configure options)
1) Install Boost.
2) ./configure
3) make
You'll definitely want to check out Mono, it might be just what you're looking for: http://monodevelop.com/