July 24th, 2024

How to develop on Windows: comparing native, MinGW, Cygwin, WSL

Developing on Windows poses challenges due to Linux-oriented tools. Solutions include MSVC, MinGW-w64, Cygwin, and WSL, each offering different compatibility and functionality for C/C++ development.

Read original articleLink Icon
How to develop on Windows: comparing native, MinGW, Cygwin, WSL

Developing on Windows presents challenges due to the predominance of tools designed for Linux, including popular software like Git. Various solutions exist, each with its pros and cons. Native development using MSVC (Microsoft Visual C/C++) is the official method, but it diverges from Linux systems. MinGW-w64 offers a Linux-like environment while producing native Windows executables, making it a viable alternative for C and C++ development. Cygwin provides a Linux-like experience on Windows but has compatibility issues due to its unique ABI, which can hinder the use of pre-built libraries.

For a more integrated Linux experience, WSL (Windows Subsystem for Linux) is recommended, particularly WSL2, which operates as a lightweight virtual machine. WSL2 supports GUI applications and offers full Linux compatibility, though it has limitations in hardware access and slower file operations between the VM and host. WSL1, while faster for accessing Windows files, lacks the full VM capabilities of WSL2.

Using tools like Scoop can simplify the installation of development software on Windows. MSYS2 combines the benefits of Cygwin and MinGW-w64, allowing for a unified environment with Linux-style build scripts. Ultimately, the choice of development environment on Windows depends on the specific needs of the project and the desired level of compatibility with Linux tools.

Related

Writing GUI apps for Windows is painful

Writing GUI apps for Windows is painful

Samuel Tulach discusses challenges in writing Windows GUI apps in C++, emphasizing requirements like Windows support, styling, and efficiency. He evaluates various frameworks, recommending Dear ImGui for its simplicity and lightweight design.

Some sanity for C and C++ development on Windows

Some sanity for C and C++ development on Windows

C and C++ development on Windows historically struggled due to limited native standard library support, causing compatibility issues, especially with non-ASCII characters. Workarounds like libwinsane address these limitations, but challenges persist despite recent improvements in Unicode support.

Solving the Worst Problem in Programming Education: Windows

Solving the Worst Problem in Programming Education: Windows

The article discusses challenges in programming education on Windows, emphasizing simplifying language installations. Zed A. Shaw highlights Windows' dominance, advocates for diverse tools, and introduces automated installation solutions for various programming languages.

Developing on Windows: Comparing Native, MinGW, Cygwin, WSL

Developing on Windows: Comparing Native, MinGW, Cygwin, WSL

Developing on Windows poses challenges with Linux tools dominance. Solutions include VMs, WSL2 for Linux experience, or native Windows tools like Cygwin. Options vary for C/C++ development, balancing integration, performance, and compatibility.

Just Use MSYS2 You Say?

Just Use MSYS2 You Say?

Zed A. Shaw critiques the suitability of MSYS2 for beginner programmers on Windows, highlighting challenges with setup, package management, and usability. He advocates for simple, user-friendly environments over complex solutions.

Link Icon 27 comments
By @skrebbel - 3 months
Nitpick, the article’s suggestion that Git badly supports Windows strikes me as about 2 decades out of date. I dev on native Windows (only using WSL for key tools like sl and cowsay) and Git has Just Worked pretty much ever since I began using it.

Maybe the only speedbump is that you gotta remember to turn off the “autocrlf” setting, which has a default from way back when there were still editors on Windows that choked on \n.

By @twiss - 3 months
> a lot of tools are made primarily for Linux. Surprisingly this even includes very popular ones like Git

A bit off-topic but this particular example becomes less surprising if you look up who created git :)

By @forrestthewoods - 3 months
> Developing on Windows can be frustrating

As a primarily Windows developer of video games I find developing on Linux far more frustrating, fragile, and error prone than Windows.

However it's less about which is better or worse, and more about the devil you know. Setting up a brand new macOS for development is excruciating. Learning Linux is an extremely long, time consuming, and painful experience. But once you've built up some scar tissue it doesn't seem so bad!

> The cleanest way is to just use Linux on Windows

Hard hard hard disagree. I could not possibly disagree more strongly. I violently and disrespectfully disagree.

> The other option is to use Windows proper

This is the way. Don't use Cygwin or MinGW-64. That is bad advice.

I write a lot of C++ code. It typically needs to run on Windows, macOS, Linux, and Android. My experience is that Windows developers are generally content to step out of their comfort zone and work on macOS and Linux "natively". My personal lived experience is that Linux-first developers are far and away the least likely to even think of Windows or other platforms. They frequently refuse to request a Windows machine so they can even test another platform. Which means I have to fix all their broken code, grumble grumble. If you hard coded /usr/lib or similar you're a bad person.

My recommendation is to simply learn Windows and do things the native Windows way. Stop assuming all platforms are Linux. Cross-platform is a solved and relatively simple problem. Trying to force everything to behave The Linux Way is pain and suffering.

Personally I think "The Linux Way" is generally quite bad. Try something different! Be open to new experiences! Don't dip your toes in the water, jump in the deep end! You might learn a thing or two. And who knows, you may even discover it's quite pleasant.

By @ryukoposting - 3 months
The author's recommendation of a MinGW-W64 toolchain + Cygwin build utilities is the workflow I followed for several years before moving to MSYS2, before ditching Windows entirely a few months ago.

WSL did its job quite well, but asking a user to set up WSL is out of the question. It isn't well-suited for anything a non-technical person might want to touch.

One thing the author doesn't make clear is that MinGW-64 does not fully implement a Linux compatibility layer. For example, if you try to use MinGW to compile a program that calls fork(), you're going to have a bad time.

That's why Cygwin is still relevant today - its compatibility layer is much more comprehensive than MinGW, at the cost of an extra DLL that has to follow your program around. Also bear in mind that Cygwin has to do some really nasty things [1] to do everything it does. Whenever you run into a situation where the Unix API doesn't align with the Windows view of the universe, Cygwin runs the risk of introducing severe performance issues.

[1] https://cygwin.com/cygwin-ug-net/highlights.html

By @tonymet - 3 months
A great summary that should encourage more Linux developers to use Windows. Lots of utility with WSL2 and Hyper-V built in, you can run any Linux distro you like with a single click from the MS Store, while enjoying the great performance and UX on Windows 11 (once you turn off the ads -- yeah I know).

I use a combination of VS Code with WSL2 Debian -- so it's identical to my prod environment. It's polished, consistent with prod and efficient on my hardware.

Compared to the Mac I find the Windows experience to be far better, because of the native Hyper-V VM support, better Linux compatibility with WSL2 and the much more diverse hardware options. The PC ecosystem is incredible.

Even the Windows ecosystem is nice, Visual Studio Community is free, the CLI compiler is available, winget makes installs easier, Powershell has a lot of utility and Windows Terminal is excellent.

Given that you can pick up a capable mini PC for about $200 , it's worth testing out. Windows is great for Linux development.

By @carom - 3 months
I've been developing on Windows the last year and a half. I came from a Linux background and wanted to learn how to use Windows in the same way I used Linux, that is to say, I wanted to avoid finding "bash on Windows" solutions and calling it a day.

My advice, install Visual Studio (or just the build tools), fire up the developer command prompt for your architecture, then learn the cl (compiler) and ml (the assembler) command line invocations. Many common Unix commands have an equivalent command prompt command you can learn. It just takes some repetition to remember them.

I will be the first to admit, it's very funky. Copy and move have some quirks (use xcopy or robocopy). Batch scripts execute in a really uninituitive way. There are a lot of rough edges but you can develop C and C++ like you would on Linux with a terminal and text editor, it just takes some getting used to.

By @invokestatic - 3 months
My go to on Windows is LLVM using the Windows SDK for libc. Before Microsoft had solved the whole msvcrt redistributable mess I used mingw-64 as the libc which worked pretty well actually.
By @qwery - 3 months
This article doesn't quite land for me. It could perhaps use an introductory paragraph explaining who it's for / what the goal is. For example, are we trying to build cross-platform software, with a single build system?

> If you want to develop C or C++ on Windows, your options get more complicated.

This is a weird thing to say. If you want to build software for Windows -- especially so in C or C++! -- your choice is simplified. The best way to build software for Windows is to use Windows tooling. MSVC is excellent at compiling standard portable C and C++ code to a native windows executable. If you write portable code, it will compile with any of the major compiler suites, for any of the platforms they (fully) support.

By @osigurdson - 3 months
If you just want basic Linux utilities, create a Windows terminal profile pointing to C:\Program Files\Git\bash.exe.

You likely have git installed anyway and this works very well. I use this all the time.

By @majoe - 3 months
Cygwin is currently the bane of my existence.

I'm working on software, that was originally written in CORAL and running on mainframes and then translated to C to run on UNIX.

Company policy is, that all programs have to run on Windows, so nowadays we work with Cygwin Don't get me wrong, it works, but there a thousand annoying things, bugs an inconveniences.

I'm currently spearheading an effort to migrate to wsl2 (and docker). The developer experience is vastly better on wsl.

By @OhMeadhbh - 3 months
+1

After falling out of love with macOS a couple decades ago, I've been using WSL/VMs on Win{7|10|11}. While I sort of detest the ads on my corporate Win11 laptop, it's what the corporation requires I use. VirtualBox on Win7 was a very usable solution. WSL1 on Win10 was a tiny bit rough, but WSL2 on Win10/11 has been pretty decent. The only problem I have is it's unclear who "owns" mDNS: windows side or leenucks side. For most of the last several years it just plain didn't work on the leenucks side. Then a work-around was published, but it seems to not work now.

But... I love small charts like this. I hadn't been thinking about cygwin or MinGW. It's good to be reminded they still exist.

By @vips7L - 3 months
The only issues I have when developing natively on Windows are when other developers on macOS don't use cross-platform tools (bash scripts). Scoop is a great package manager, and with windows-terminal + powershell you can't really ask for anything better.
By @anthk - 3 months
Something about synchronicity, serendipia, Jung, David F.Peat... must be true, because I've been trying to compile stuff with mingw for days and then it's not odd to see that either at HN, Reddit or the Spanish Digg/Reddit clone.

Jokes being put aside, I've got to cross-compile Kristall for MinGW (Windows 32 bit target, for W7), but it required tons of deps and it the end it gave me errros on some libs, so I will rebuild it statically with the full src in a parallel tgz. At least it launched with an error under Wine (dynamic binary), so I can say mingw32 works fine.

I tried to the same with Lagrange, but it gave me an error on libUnistring. As the $DISTRO I use didn't provide it as a MinGW package, I gave up.

By @CLiED - 3 months
Just download the latest visual studio, no need for gimmicks or trying to reproduce the unix dev experience on windows, just embrace the platform, warts and all, and call it a day.
By @commercialnix - 3 months
If you are going to develop on Windows and you aren't developing for Windows, you are what the construction and film production industries call "green".
By @atVelocet - 3 months
I don’t like this article as it seems the author did not dive a bit into some of the topics he mentions. As an example I wanna point out WSL2 and USB support:

https://github.com/dorssel/usbipd-win

This is the recommended way and works as expected. It is also possible to directly mount WSL2 drives with near native performance.

By @axus - 3 months
I had a lot of fun using MSYS2 / MinGW64 and building things for Windows, but I can't imagine it being fun for most people.

Installing git-for-windows was an easy way to try it out, to see if that rabbit hole is for you.

By @michaelsbradley - 3 months
MSYS2 plus its CLANG64 environment is great stuff:

https://www.msys2.org/docs/environments/

By @rubymamis - 3 months
Honestly, Qt C++ & QML is the best way to develop on Windows (and Linux). Soon enough, I'll also prove it's the best for macOS (under some specific expectations).
By @paul_manias - 3 months
I've been using MinGW and MSYS for Windows development since the early 2000's, mainly to keep the build process consistent with Linux. A couple of years ago I gave Visual Studio / MSVC a second chance and have stuck with it ever since.

MSVC generates significantly faster & smaller code, doesn't require additional DLLs in the final build, and the C++ compiler behaves predictably. Critically it also works very well with CMake, so my build process is seamlessly aligned with Linux.

The VS debugger is a major help too - gdb can do the same stuff, and there are UIs for gdb, but debugging through VS is just more productive and convenient. Times change!

By @trimethylpurine - 3 months
I think this headline should read specific to C/C++ for Linux.

I'm still not sure that I agree with the above, but I do know for sure I couldn't say this about Python, Java, Go, web, etc. because development on Windows for any of these most popular languages is braindead simple in those cases. In fact it's much easier than setting up in Linux or Mac for the same thing. Especially in a multi platform enterprise environment with lots of security controls and a need for cross platform file sharing.

To put this in perspective, this article is a tour of trying to do cross platform development in C/C++ on the only desktop OS that it's reasonable to do that in at all.

By @42lux - 3 months
Everytime I read articles like this no one brings up that wsl caches file transfers in RAM. With large enough transfers it slows your machine to a halt. It's infuriating and made me switch to Linux for heavy workloads.
By @drillsteps5 - 3 months
The better name of the article would be "What to do if you only developed in Linux and now need to develop under Windows but are too lazy to learn the tools and best practices within Windows ecosystem". There's also much simpler way - spin up a VM with Linux and continue developing there.

Or you can, you know, learn to develop with Visual Studio, Azure, and entire development ecosystem built by MSFT in the last few decades.

And btw Git might have been built by Torvalds but GitHub is owned by Microsoft :)

By @delta_p_delta_x - 3 months
Here we go: a thread on developing for Windows, and immediately there are several top-level comments saying 'don't'. I suppose you guys like leaving 75% of a potential install base out of consideration. More money for us Windows devs, I guess.

After having recently worked on a project at work that involved precisely this (migrating a Linux/macOS-first project to Windows), I feel like that table at the top is... not the whole story. I also disagree with the author's conclusion: the easiest and most compatible way to develop on Windows is to use Visual Studio 2022, full stop. Download, install the Desktop Development with C++ workload, and start writing code. Can't be easier. It comes with a built-in debugger, profiler, and various build tools like CMake, Ninja (if you don't like MSBuild/NMake), Clang-CL (if you don't like cl.exe), and much more.

My background is a little different to the author: I've been writing on and for Windows most of the time, and I was only introduced to Linux in university. In order of 'closeness to Linux':

- WSL1/2: these are for all intents and purposes Linux VMs (yes, not in the case of WSL1, but practically it might as well be). Use these as though you would a real Linux machine.

- Cygwin: in general, never use Cygwin for new projects. Cygwin means saddling your user with an entire Linux filesystem hierarchy per application, including stuff like `/bin`, `/etc`, `/lib`, and so on. Additionally, it pretends to support `fork()` on Windows. Windows and NT don't have fork(). Never had, and never will. Don't use it, full stop.

- MinGW: this targets the Itanium C++ ABI. An admirable but sadly incomplete effort. New Win32 APIs like cfapi.h[1] aren't available. Big Windows-specific libraries like Microsoft's WIL[2] cannot compile on MinGW because they rely on MSVC-specific extensions. Deal-breaker for me.

- MSVC providing cl.exe, and also LLVM's official Clang releases for Windows: best options. These target the MSVC C++ ABI and expect/provide a complete install of the Windows SDK and MSVC C and C++ runtimes.

In general, I dislike shoehorning Linux/UNIX onto Windows and vice versa.

System developers should recognise the differences between OS and platform-specific primitives, APIs, and interfaces, and abstract over them depending on their needs. Each implementation should live on its own and should be linked to by the build system, and not directly interspersed in code. This means no `#ifdef _WIN32 #elifdef DARWIN #elifdef __linux`.

Or—and a hot take incoming—if you don't want to do any of this, use a platform-independent managed/interpreted language like Java, C#, Go, or Python.

[1]: https://learn.microsoft.com/en-us/windows/win32/api/cfapi/

[2]: https://github.com/microsoft/wil/issues/117

By @externedguy - 3 months
Switch to Linux
By @neilv - 3 months
> The cleanest way is to just use Linux on Windows, via a full VM, or through WSL2, which is a lightweight, well-integrated VM.

The cleanest way is to get a job that doesn't require you to develop on Microsoft Windows.

Then you can just use Debian Stable, or some other decent Linux distro.