如何在 Visual Studio 2010 for Linux 中编译
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9171414/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to compile in Visual Studio 2010 for Linux
提问by schoetbi
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)?
是否可以使用 Visual Studio 2010(不一定是 MSVC 编译器)在 Windows 上开发 C/C++ 并获取我可以上传到 linux 机器(并运行它)的二进制文件?
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).
我检查过的可能性是使用 MinGW 或类似的东西来让 Windows 二进制文件做与 linux 二进制文件相同的事情,但是我在获取所有需要的库(posix)的所有 win 端口时遇到了问题。
EDIT: I do not want to let the windows binary run on linux. I need a native linux binary as a result.
编辑:我不想让 windows 二进制文件在 linux 上运行。因此,我需要一个本机 linux 二进制文件。
采纳答案by schoetbi
Thanks to all of you! My solution is summarized:
感谢大家!我的解决方案总结如下:
- Platform-independent code is developed using Visual Studio
- Final Build (for Linux) is performed using a Virtual Box running Debian or RHEL
- IDE within the Virtual Box is Eclipse with the CDT plugin
- Use CMake To generate the project files for both Visual Studio and Eclipse CMake
- 使用 Visual Studio 开发独立于平台的代码
- 使用运行 Debian 或 RHEL 的 Virtual Box 执行最终构建(适用于 Linux)
- Virtual Box 中的 IDE 是带有 CDT 插件的 Eclipse
- 使用 CMake 为 Visual Studio 和 Eclipse CMake 生成项目文件
回答by Basile Starynkevitch
No, I don't think that you can cross-compile targetting Linux/x86 with a visual studio compiler.
不,我不认为您可以使用 Visual Studio 编译器交叉编译针对 Linux/x86 的目标。
(I don't know Windows, but I heard that Microsoft is not very friendly towards Linux and does not develop cross-compilers)
(我不懂Windows,但听说微软对Linux不是很友好,不开发交叉编译器)
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).
为 Linux/x86 编译代码的最简单方法是安装完整的 Linux 发行版(在您的笔记本电脑上,或者可能在虚拟机中)。
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.
您也许可以编译(对于 Windows 主机)GCC 和 binutils 以获得针对 Linux/x86 并在 Windows 上运行的交叉编译器,但我不会向新手推荐它。
(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!)
(如果你整个团队只懂Windows,你需要花费资源让团队学习Linux,如果每个开发者的桌面上都有Linux系统那就更容易了。当然学习需要时间、精力和成本;并且大部分精力将用于学习 Linux 下的编程,例如 Linux 系统调用和常用 API 和库;因此,保留 Visual 不会有太大好处,而且会花费您!)
回答by PatrickV
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?
我对此有一些意见,但如果没有更多信息,很难权衡。为什么要在 Visual Studio 中进行开发?您的目标是什么类型的应用程序?是否已经存在一定程度的代码成熟度?是否存在影响此决定的团队经验问题?
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.
我的下意识反应是,在开发要在 Linux 环境中使用的应用程序时,您似乎想要 VS 2010 开发环境在开发人员生产力方面的优势。如果我面临这种情况,我可能会在基于 Linux 的恒定集成服务器上使用 mono 使用具有短期签入(一小时左右应该没问题)的可移植 C#,以清除不可移植的代码. 但是,您指定了 C++,因此假设这是一项要求,这可能不适合您。
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.
将 C++ 作为硬性要求,将 Visual Studio 作为硬性要求,您发布的计划听起来不错。此外,我肯定希望在目标平台上运行一个持续集成服务器并进行短期签入,以防止对非可移植代码进行任何重要的代码开发。如果您拥有 MSDN 许可证(并在 Visual Studio 和 Eclipse 中提供工具集成),TFS 可以处理此问题。还有很多其他不错的选择,但您似乎被 Microsoft 堆栈所吸引。