如何在 Microsoft Visual Studio 中使用 GCC? [英] How to use GCC with Microsoft Visual Studio?

查看:175
本文介绍了如何在 Microsoft Visual Studio 中使用 GCC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个非常大的项目(几千行),所以不想使用 Notepad++.IDE 会让它变得更容易.我有使用 Microsoft Visual Studio 的经验并且喜欢它.是否有一些简单的方法可以在 Microsoft Visual Studio 中使用 Cygwin 的 GCC?

I am creating a very large project (a few thousand lines) and so would rather not use Notepad++. An IDE would make it so much easier. I have experience with Microsoft Visual Studio and love it. Is there some easy way to use Cygwin's GCC from within Microsoft Visual Studio?

或者,除了 NetBeans 和 Eclipse 之外,还有其他适用于 GCC 的优秀 Windows IDE 吗?(我非常讨厌他们两个.)

Alternately, are there any other good Windows IDEs for GCC besides NetBeans and Eclipse? (I hate both of them with a passion.)

推荐答案

这里有几种方法:

Visual Studio 2005 和更新版本将允许您注册自定义构建工具.它们告诉 IDE 如何将一种形式的文件(例如 .cpp 文件)转换为另一种形式(例如 .obj 文件).

Visual Studio 2005 and newer will let you register custom build tools. They tell the IDE how to transform files of one form (e.g. a .cpp file) into another form (e.g. an .obj file).

据我所知,还没有人为 GCC 做过这件事.而且,自己动手需要编写 COM 代码,这可能太深了,无法仅针对单个项目深入研究.你必须有一个令人信服的理由来接受这个项目.

So far as I know, no one has done this yet for GCC. And, doing it yourself requires writing COM code, which is probably too deep a pool to dive into just for a single project. You'd have to have a compelling reason to take this project on.

然后您必须手动调整每个项目以告诉它使用自定义构建工具而不是默认构建工具,因为您使用的是 Visual C++ 的文件扩展名(.cpp,可能)已经知道了.如果您尝试为从多个模块构建的单个可执行文件混合使用 VC++ 和 g++ 编译器,则会遇到麻烦.

You then have to manually adjust each project to tell it to use the custom build tool instead of the default, since you're using a file name extension (.cpp, probably) that Visual C++ already knows about. You'll run into trouble if you try to mix the VC++ and g++ compilers for a single executable built from multiple modules.

从好的方面来说,如果您想开始一个开源项目,这对我来说听起来不错.我希望你能很快聚集一个庞大的用户群.

On the plus side, if you were looking to start an open source project, this sounds like a good one to me. I expect you'd quickly gather a big user base.

  1. 启动 Visual Studio 并说文件 > 新建项目.

  1. Start Visual Studio and say File > New Project.

在 Visual C++ 部分,选择 Makefile Project

In the Visual C++ section, select Makefile Project

填写 Makefile 项目向导:

Fill out the Makefile Project Wizard:

  • 构建命令行: make
  • 清理命令:ma​​ke clean
  • 重建命令行: make clean all
  • Build command line: make
  • Clean commands: make clean
  • Rebuild command line: make clean all

如果您以项目名称命名了可执行文件,并且它位于 Visual Studio 期望找到的位置,则可以单独保留 输出(用于调试) 字段.

You can leave the Output (for debugging) field alone if you've named your executable after the project name and it lands where Visual Studio expects to find it.

不要管其余的字段,除非您知道它们是什么以及为什么要更改它们.例如,您可以选择在 预处理器定义 行上传递 -D 标志以获得单独的调试和发布输出.如果你知道你想要这个,你就知道如何设置它,所以我不会为了解释它而延长这个长答案.

Leave the rest of the fields alone unless you know what they are and why you want to change them. As an example, you might choose to pass a -D flag on the Preprocessor definitions line to get separate debug and release outputs. If you know you want this, you know how to set it up, so I'm not going to make this long answer even longer in order to explain it.

对于发布版本,您会被问到同样的问题.如果您想打扰单独的调试和发布版本,您可以在此处进行任何更改.

You'll be asked the same set of questions for the Release build. If you want to bother with separate debug and release builds, you'd make any changes here.

完成所有这些后,您仍然需要创建 Makefile,并将 make.exe 添加到您的 PATH.与调试与发布问题一样,深入到这种程度的细节会使这个答案偏离主题.

Having done all this, you still have to create the Makefile, and add a make.exe to your PATH. As with the debug vs. release question, going into that level of detail would push this answer off topic.

尽管看起来很丑陋,但它仍然比创建自定义构建工具更容易.另外,你说你最终需要移植到 Unix,所以你无论如何都需要 Makefile.

As ugly as this looks, it's still easier than creating custom build tools. Plus, you say you need to port to Unix eventually, so you're going to need that Makefile anyway.

您说您想在某个时候将该程序移植到 Unix,但这并不意味着您现在必须在 Windows 上使用 GCC.很可能编写您的程序,使其在 Windows 上的 Visual C++ 和 *ix 系统上的 GCC/Makefiles 下构建.

You say you want to port this program to Unix at some point, but that doesn't mean you must use GCC on Windows now. It is quite possible to write your program so that it builds under Visual C++ on Windows and GCC/Makefiles on *ix systems.

有几种工具可以使这变得更容易.一个非常流行的选项是 CMake,它在较新版本的 Visual Studio 中作为安装时间选项提供.有许多替代方案,例如 SCons烘焙文件.

There are several tools that make this easier. One very popular option is CMake, which is available as an installation time option in newer versions of Visual Studio. There are many alternatives such as SCons and Bakefile.

这篇关于如何在 Microsoft Visual Studio 中使用 GCC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆