简体   繁体   English

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

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

Basically I want to compile C/C++ using the GCC on Windows. 基本上我想在Windows上使用GCC编译C / C ++。 The two competing platforms, as i see it, are MinGW and Cygwin. 正如我所看到的,两个竞争平台是MinGW和Cygwin。 Each have their own benifits and limitations. 每个都有自己的好处和限制。 MinGW compiles for Windows, whereas Cygwin needs the cygwin .dll. MinGW为Windows编译,而Cygwin需要cygwin .dll。 However installing libraries on MinGW is difficult, whereas on cygwin it's easier, using the setup.exe as a 'package manager'. 但是在MinGW上安装库很困难,而在cygwin上使用setup.exe作为“包管理器”则更容易。

My question is what's the best way to compile on Windows. 我的问题是在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). 使用MinGW并与图书馆斗争会更好(在这种情况下,有一种简单的方法可以在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. 或者我应该使用Cygwin,如果是这样我如何在不需要cygwin .dll的情况下编译它,有效地编译正常的Windows。

The easiest and best way to compile on windows is to use visual studio expres s. 在Windows上编译的最简单和最好的方法是使用visual studio expres It is free. 这是免费的。 A good reason for using cygwin is for cross platform builds. 使用cygwin的一个很好的理由是跨平台构建。 A good reason to use gcc is it supports some compiler candy the Microsoft compiler doesn't. 使用gcc的一个很好的理由是它支持微软编译器没有的一些编译器糖果。

But all in all VC++ Express is the way to go for windows only development. 但总而言之,VC ++ Express是开发Windows的方法。

There is always the option of using -mno-cygwin with Cygwin to compile against Windows libraries like MinGW does: 总是可以选择使用-mno-cygwin和Cygwin来编译像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. Qt Creator允许你在Windows上使用MinGW进行编译(在Linux上使用gcc,...),有一个IDE,它使调试比gdb更友好。 If you need libraries, you still have the option of using the Qt libraries. 如果您需要库,您仍然可以选择使用Qt库。 That would be a good alternate solution to the Visual Studio if you really want to stick to gcc for future portability. 如果你真的想坚持使用gcc以便将来移植,那将是Visual Studio的一个很好的替代解决方案。

You might want to look at CodeBlocks . 您可能希望查看CodeBlocks It is generally used to build WxWidgets apps, but it wraps MinGW nicely. 它通常用于构建WxWidgets应用程序,但它很好地包装了MinGW。

Qt Creator标配MinGW,可用于构建实际不使用Qt框架的项目。

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 . 实际上,有选项#3:如果您的Windows版本允许,您可以安装Microsoft Services for Unix / Subsystem for Unix Applications ,然后从SUACommunity获取gcc。 It has a package manager, too. 它也有一个包管理器。 Of those 3 options, this will give you behavior closest to a true Unix system. 在这3个选项中,这将为您提供最接近真正Unix系统的行为。

However, the resulting applications aren't Win32 applications; 但是,生成的应用程序不是Win32应用程序; they're SUA applications, and will require SUA to run. 它们是SUA应用程序,需要SUA才能运行。 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. 如果你自己编写代码,如果你自己编写代码通常不是问题,但是如果你想编写和发布一个合适的Windows应用程序,我建议远离任何试图模仿Unix的东西,所以MinGW就是这样。

There's an easy to install MinGW wrapped GCC at equation.com . equation.com上有一个易于安装的MinGW包装GCC。 Click "Programming Tools" then "Fortran, C, C++", download the release you prefer, install and use. 单击“编程工具”,然后单击“Fortran,C,C ++”,下载您喜欢的版本,安装和使用。

One possible method is to use CMake which can build Visual Studio project from your sources and then compile from Visual Studio. 一种可能的方法是使用CMake ,它可以从您的源构建Visual Studio项目,然后从Visual Studio编译。 It can build project for other IDEs too, so you can go cross platform. 它也可以为其他IDE构建项目,因此您可以跨平台。

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. 我认为答案取决于您是打算使用库还是编译针对POSIX或基于POSIX的目标的程序。 That's what Cygwin is intended for, while MinGW is more intended for compiling Windows-targeted programs using GCC. 这就是Cygwin的目的,而MinGW更倾向于使用GCC编译以Windows为目标的程序。

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. 它基本上是MinGW的非官方分支,最新的GCC编译器可用于32位和64位Windows机器。 Even some MinGW developers themselves use it. 甚至一些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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Linux到Windows移植C / C ++代码的最佳环境 - Best environment to port C/C++ code from Linux to Windows 如何设置VSCode以使用Visual C ++ Build Tools for Windows - How to setup VSCode to use Visual C++ Build Tools for Windows 在多线程环境(C ++)中读写文件的最佳方法 - Best way to read/write file in multithreaded environment (C++) 有没有办法在Windows上以C ++编程方式设置环境路径? - Is there a way to set the environment path programmatically in C++ on Windows? 关于应用程序速度,最佳的C ++编译器和Windows构建选项? - Best C++ compiler and options for windows build, regarding application speed? 构建与Android应用程序通信的C ++程序的最佳方法 - Best way to build a C++ program that communicates with an Android app 无法设置本地C ++开发环境 - Unable to setup local C++ dev environment 在 Windows 中使用 C++ 截取窗口屏幕截图的最佳方法是什么? - What is the best way to take screenshots of a Window with C++ in Windows? 检测Windows C ++中缓冲区溢出源的最佳方法是什么? - what is the best way to detect the source of buffer overflow in c++ for windows? C ++模板/通用/元编程的最佳设置 - Best setup for c++ template/generic/metaprogramming
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM