Search…
MSYS2
MSYS2 is a popular build system for Windows based on mingw-w64 and includes both gcc and clang compilers. MSYS2 uses a package manager named pacman (a port from arch-linux) and has about 2000 precompiled mingw-packages. MSYS2 is designed to build standalone software: the binaries built with mingw-w64 compilers do not depend on MSYS2 itself[^1].

Get curl and libcurl on MSYS2

Current information about the mingw-w64-curl package can be found on the msys2 website: https://packages.msys2.org/base/mingw-w64-curl. Here we can also find installation instructions for the various available flavors. For example to install the default x64 binary for curl we run:
1
pacman -Sy mingw-w64-x86_64-curl
Copied!
This package contains both the curl command line tool as well as libcurl headers and shared libraries. The default curl packages are built with the OpenSSL backend and hence depend on mingw-w64-x86_64-openssl. There are also mingw-w64-x86_64-curl-gnutls and mingw-w64-x86_64-curl-gnutls packages, refer to the msys2 website for more details.
Just like on Linux, we can use pkg-config to query the flags needed to build against libcurl. Start msys2 using the mingw64 shell (which automatically sets the path to include /mingw64) and run:
1
pkg-config --cflags libcurl
2
# -IC:/msys64/mingw64/include
3
4
pkg-config --libs libcurl
5
# -LC:/msys64/mingw64/lib -lcurl
Copied!
The pacman package manager installs precompiled binaries. Next up we explain how to use pacman to build curl locally, for example to customize the configuration.

Building libcurl on MSYS2

Building packages with pacman is almost just as simple as installing. The entire process is contained in the PKGBUILD file from the mingw-w64-curl package. We can easily modify the file to rebuild the package ourselves.
If we start with a clean msys2 installation, we first want to install some build tools, like autoconf, patch and git. Start the msys2 shell and run:
1
# Sync the repositories
2
pacman -Syu
3
4
# Install git, autoconf, patch, etc
5
pacman -S git base-devel
6
7
# Install GCC for x86_64
8
pacman -S mingw-w64-x86_64-toolchain
Copied!
Now clone the mingw-packages repository and go to the mingw-w64-curl package:
1
git clone https://github.com/msys2/MINGW-packages
2
cd MINGW-packages/mingw-w64-curl
Copied!
This directory contains the PKGBUILD file and patches that are used for building curl. Have a look at the PKGBUILD file to see what is going on. Now to compile it, we can do:
1
makepkg-mingw --syncdeps --skippgpcheck
Copied!
That is it. The --syncdeps parameter will automatically check and prompt to install dependencies of mingw-w64-curl if these are not yet installed. Once the process is complete you will have 3 new files in the current directory, for example:
  • pacman -U mingw-w64-x86_64-curl-7.80.0-1-any.pkg.tar.zst
  • pacman -U mingw-w64-x86_64-curl-gnutls-7.80.0-1-any.pkg.tar.zst
  • pacman -U mingw-w64-x86_64-curl-winssl-7.80.0-1-any.pkg.tar.zst
Use the pacman -u command to install such a local package file:
1
pacman -U mingw-w64-x86_64-curl-winssl-7.80.0-1-any.pkg.tar.zst
Copied!
Have a look at the msys2 docs or join the gitter to learn more about building with pacman and msys2!
[^1]: Be careful not to confuse the mingw-package mingw-w64-curl with the msys-packages curl and curl-devel. The latter are part of msys2 environment itself (e.g. to support pacman downloads), but not suitable for redistribution. To build redistributable software that does not depend on MSYS2 itself, you always need mingw-w64-… packages and toolchains.
Last modified 3mo ago
Export as PDF
Copy link
Edit on GitHub