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

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

问题描述

我创建了一个非常大的项目(几千行),所以不想使用Notepad ++。 IDE将使它变得更容易。我有Microsoft Visual Studio的经验和喜欢它。有没有一些简单的方法使用Cygwin的GCC从Microsoft Visual Studio?

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

推荐答案

有几种方法可以到这里:

There are a couple of ways to go here:

Visual Studio 2005及更高版本将让您注册自定义构建工具。他们告诉IDE如何将一种形式的文件(例如 .cpp 文件)转换为另一种形式(例如 .obj file)。

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项目

In the Visual C++ section, select Makefile Project

如果您使用的是Visual Studio Express,请不要选中将项目检查为源代码控制的框。如果你不支付Visual Studio,你可能也选择不支付微软昂贵的团队解决方案,VSE不支持第三方 VCS 插件,例如 AnkhSVN Subversion

Don't check the box offering to check the project into source control if you're using Visual Studio Express. If you're not paying for Visual Studio, you're probably also choosing not to pay for Microsoft's expensive Team "solutions," and VSE doesn't support third-party VCS plugins, such as AnkhSVN for Subversion.

填写Makefile项目向导:

Fill out the Makefile Project Wizard:


  • 构建命令行: make

  • 清除命令:清除

  • 重新构建命令行 >
  • Build command line: make
  • Clean commands: make clean
  • Rebuild command line: make clean all

保留 Output(for debugging)字段,除非你做了一些奇怪的事情,项目名称或将可执行文件名称放在项目顶层以外的位置。

Leave the Output (for debugging) field alone, unless you're doing something odd like not naming your executable after the project name, or putting the executable name somewhere other than the top level of the project.

保留其余的字段,除非你知道它们是什么,为什么你想改变它们。作为示例,您可以选择在预处理器定义行上传递 -D 标志,以获取单独的调试和发布输出。如果你知道你想要这个,你知道如何设置它,所以我不会让这个长的答案更长,为了解释它。 (如果你不知道如何,但想要,这可能是一个新的SO问题的好话题!)

Leave the rest of the fields alone, unless you know what they are and why you want to change them. Just 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. (And if you don't know how but want to, it's probably a good topic for a new SO question!)

你会被问同一组问题用于发布版本。如果你想打扰单独的调试和发布版本,你可以在这里做任何更改。

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 ,并向 PATH 中添加 make.exe 。与调试与发布问题一样,进入该级别的详细信息将推送此回答关闭主题。

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.

甚至有几个工具, ,通过从单个公共源生成VS项目文件和 Makefile 。我碰巧使用烘焙文件,但 CMake 近年来越来越受欢迎。 SCons 也执行此工作,并且可能也比Bakefile更受欢迎;它肯定会更新更频繁。

There are even several tools that make this easier, by generating VS project files and Makefiles from a single common source. I happen to use Bakefile, but CMake has become more popular in recent years. SCons also does this job, and is probably also more popular than Bakefile; it's certainly updated more often.

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

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