How to compile in Visual Studio 2010 for Linux

2019-03-11 04:22发布

Is it possible to develop C/C++ on Windows using Visual Studio 2010 (not necessarily the MSVC Compiler) and get a binary that I can upload to a linux machine (and run it)?

On possibility I checked was to use MinGW or something similar to get windows binaries doing the same thing that linux binaries would do but I had problems to get all win-ports for all needed libraries (posix).

EDIT: I do not want to let the windows binary run on linux. I need a native linux binary as a result.

3条回答
欢心
2楼-- · 2019-03-11 05:08

No, I don't think that you can cross-compile targetting Linux/x86 with a visual studio compiler.

(I don't know Windows, but I heard that Microsoft is not very friendly towards Linux and does not develop cross-compilers)

The easiest way for you to compile your code for Linux/x86 is to install a complete Linux distribution (on your laptop, or perhaps in a virtual machine).

You could perhaps compile (for Windows host) GCC and binutils to get a cross-compiler targetting Linux/x86 and running on Windows, but I won't recommend that to a newbie.

(If you have an entire team knowing only Windows, you need to spend resources to have the team learn Linux, and that is easier if each developer has a Linux system on his desktop. Of course learning take time, effort, and has some cost; and most of the efforts will be spent in learning programming under Linux, e.g. the Linux system calls and common APIs and libraries; so keeping Visual is not going to win much, and will cost you!)

查看更多
别忘想泡老子
3楼-- · 2019-03-11 05:12

Thanks to all of you! My solution is summarized:

  1. Platform-independent code is developed using Visual Studio
  2. Final Build (for Linux) is performed using a Virtual Box running Debian or RHEL
  3. IDE within the Virtual Box is Eclipse with the CDT plugin
  4. Use CMake To generate the project files for both Visual Studio and Eclipse CMake
查看更多
Emotional °昔
4楼-- · 2019-03-11 05:17

I have some opinions on this, but it is hard to weigh in without more information. Why is it that you want to develop in Visual Studio? What type of application are you targeting? Is there a level of code maturity that already exists? Are there team experience issues influencing this decision?

My knee-jerk reaction is that it sounds like you want the benefits of the VS 2010 development environment in terms of developer productivity while developing an application to be used in a Linux environment. If I were faced with that, I would probably be targeting portable C# using mono on a Linux-based constant integration server with short-term check-ins (once an hour or so should be fine) in order to weed out non-portable code. However you specified C++, so that's probably not a perfect fit for you assuming that is a requirement.

With C++ as a hard requirement, and Visual Studio as a hard requirement, the plan you posted sounds like a good one. In addition I would definitely want a constant integration server running on the target platform with short-term check-ins to prevent any significant code development of non-portable code. TFS can handle this if you have MSDN licenses (and provides for tool integration in both Visual Studio and Eclipse). There are plenty of other good options as well, but you seem to be drawn toward the Microsoft stack.

查看更多
登录 后发表回答