为 C/C++ 设置 Windows 构建环境的最佳方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1639519/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:20:46  来源:igfitidea点击:

Best way to setup a Windows build environment for C/C++

c++cwindowscygwinmingw

提问by AndrewM

Basically I want to compile C/C++ using the GCC on Windows. The two competing platforms, as i see it, are MinGW and Cygwin. Each have their own benifits and limitations. MinGW compiles for Windows, whereas Cygwin needs the cygwin .dll. However installing libraries on MinGW is difficult, whereas on cygwin it's easier, using the setup.exe as a 'package manager'.

基本上我想在 Windows 上使用 GCC 编译 C/C++。在我看来,两个相互竞争的平台是 MinGW 和 Cygwin。每个都有自己的优点和局限性。MinGW 为 Windows 编译,而 Cygwin 需要 cygwin .dll。然而,在 MinGW 上安装库很困难,而在 cygwin 上更容易,使用 setup.exe 作为“包管理器”。

My question is what's the best way to compile on Windows. Would it be better to use MinGW and struggle with libraries (in which case is there an easy way of installing libraries on MinGW). Or should I use Cygwin, if so how do I get it to compile without needing the cygwin .dll, effectively compile for normal Windows.

我的问题是在 Windows 上编译的最佳方式是什么。使用 MinGW 并与库斗争会更好吗(在这种情况下,有一种在 MinGW 上安装库的简单方法)。或者我应该使用 Cygwin,如果是这样,我如何在不需要 cygwin .dll 的情况下编译它,有效地为普通 Windows 编译。

回答by Byron Whitlock

The easiest and best way to compile on windows is to use visual studio express. It is free. A good reason for using cygwin is for cross platform builds. A good reason to use gcc is it supports some compiler candy the Microsoft compiler doesn't.

在 Windows 上编译的最简单和最好的方法是使用Visual Studio 表达。这是免费的。使用 cygwin 的一个很好的理由是跨平台构建。使用 gcc 的一个很好的理由是它支持一些微软编译器不支持的编译器糖果。

But all in all VC++ Express is the way to go for windows only development.

但总而言之,VC++ Express 是仅用于 Windows 开发的方法。

回答by RedGlyph

There is always the option of using -mno-cygwinwith Cygwin to compile against Windows libraries like MinGW does:

总是可以选择使用-mno-cygwinCygwin 来像 MinGW 那样针对 Windows 库进行编译:

gcc -mno-cygwin file.c -o test

It's not an easy choice and mainly depends on how much you will rely on other libraries. Cygwin really adds an additional layer, which is heavier but "emulates" the Linux environment better than MinGW.

这不是一个容易的选择,主要取决于您对其他库的依赖程度。Cygwin 确实增加了一个额外的层,它比 MinGW 更重但“模拟”Linux 环境更好。

Edit:

编辑:

Qt Creator allows you to compile with MinGW on Windows (and gcc on Linux, ...), has an IDE that makes debugging more friendly than gdb. If you need libraries, you still have the option of using the Qt libraries. That would be a good alternate solution to the Visual Studio if you really want to stick to gcc for future portability.

Qt Creator 允许您在 Windows 上使用 MinGW 进行编译(以及在 Linux 上使用 gcc,...),具有使调试比 gdb 更友好的 IDE。如果您需要库,您仍然可以选择使用 Qt 库。如果您真的想坚持使用 gcc 以实现未来的可移植性,那将是 Visual Studio 的一个很好的替代解决方案。

回答by epotter

You might want to look at CodeBlocks. It is generally used to build WxWidgets apps, but it wraps MinGW nicely.

您可能想查看CodeBlocks。它通常用于构建 WxWidgets 应用程序,但它很好地包装了 MinGW。

回答by Rob

Qt Creatorcomes with MinGW as standard and can be used to build projects that don't actually use the Qt framework.

Qt Creator带有 MinGW 作为标准,可用于构建实际上不使用 Qt 框架的项目。

回答by Pavel Minaev

Actually, there's option #3: if your edition of Windows permits it, you can install Microsoft Services For Unix / Subsystem for Unix Applications, and then get gcc from SUACommunity. It has a package manager, too. Of those 3 options, this will give you behavior closest to a true Unix system.

实际上,还有选项 #3:如果您的 Windows 版本允许,您可以安装Microsoft Services For Unix / Subsystem for Unix Applications,然后从SUACommunity获取 gcc 。它也有一个包管理器。在这 3 个选项中,这将使您的行为最接近真正的 Unix 系统。

However, the resulting applications aren't Win32 applications; they're SUA applications, and will require SUA to run. If you write code for yourself, it's usually not a problem if you write code for yourself, but if you want to write and distribute a proper Windows application, I would suggest staying away from anything that tries to emulate Unix, so MinGW it is.

但是,生成的应用程序不是 Win32 应用程序;它们是 SUA 应用程序,需要 SUA 才能运行。如果您为自己编写代码,那么为自己编写代码通常不是问题,但是如果您想编写和分发合适的 Windows 应用程序,我建议您远离任何试图模拟 Unix 的东西,所以是 MinGW。

回答by Michael Burr

I think the answer depends on whether you intend to use libraries or compile programs that are targeted to POSIX or a POSIX-based target. That's what Cygwin is intended for, while MinGW is more intended for compiling Windows-targeted programs using GCC.

我认为答案取决于您是打算使用库还是编译针对 POSIX 或基于 POSIX 的目标的程序。这就是 Cygwin 的用途,而 MinGW 更适用于使用 GCC 编译面向 Windows 的程序。

回答by TyTN

Another option is TDM MinGW: http://www.tdragon.net/recentgcc/

另一种选择是 TDM MinGW:http: //www.tdragon.net/recentgcc/

It's basically an unofficial fork of MinGW with the latest GCC compiler available for both 32- and 64bit windows machines. Even some MinGW developers themselves use it.

它基本上是 MinGW 的非官方分支,具有适用于 32 位和 64 位 Windows 机器的最新 GCC 编译器。甚至一些 MinGW 开发人员自己也在使用它。

Equation Gcc is even better: http://www.equation.com/servlet/equation.cmd?fa=fortran

方程 Gcc 甚至更好:http: //www.equation.com/servlet/equation.cmd?fa=fortran

回答by oold

One possible method is to use CMakewhich can build Visual Studio project from your sources and then compile from Visual Studio. It can build project for other IDEs too, so you can go cross platform.

一种可能的方法是使用CMake,它可以从您的源代码构建 Visual Studio 项目,然后从 Visual Studio 编译。它也可以为其他 IDE 构建项目,因此您可以跨平台。

回答by pmg

There's an easy to install MinGW wrapped GCC at equation.com. Click "Programming Tools" then "Fortran, C, C++", download the release you prefer, install and use.

equation.com 上有一个易于安装的 MinGW 包装 GCC 。单击“编程工具”,然后单击“Fortran、C、C++”,下载您喜欢的版本,安装和使用。