🧰 Beyond Pacman: Unlocking Boost for MinGW with Vcpkg on Windows🛠️

As a C++ developer, diving into powerful libraries like Boost is almost inevitable. It offers an incredible suite of tools, from smart pointers to advanced networking. However, if you're working on Windows with an MSYS2/MinGW setup, getting Boost up and running can sometimes feel like an epic quest with dragons and endless dead ends. I recently embarked on this very adventure, and I want to share the twists, turns, and ultimately, the solution that finally worked for me.

🧪 The Initial Attempt: Using MSYS2's pacman

⚙️ My Environment:

  • MSYS2 with UCRT64 toolchain

  • MinGW-w64 GCC

  • Windows 10

I started with the obvious:

pacman -S mingw-w64-ucrt-x86_64-boost

🟢 Success! Or so I thought...

I then tried to compile a simple microservice:

g++ -g genericMicroservice.cpp -o genericMicroservice.exe \
-I /ucrt64/include \
-L /ucrt64/lib \
-lboost_system -lws2_32 -std=c++17

🚫 Boom.

cannot find -lboost_system: No such file or directory
collect2.exe: error: ld returned 1 exit status

Despite pacman's success message, the linker couldn't locate Boost. I verified paths, reinstalled, updated, and even yelled at the sky. No luck.

🧩 Root Cause:
libboost_system.a or libboost_system.dll.a simply didn’t exist with the expected names or locations. Pacman’s Boost wasn't aligned with my MinGW configuration.

🔄 Pivoting to Vcpkg: New Hope (and New Dragons) 🐉

After much head-scratching with pacman, I turned to Vcpkg. This fantastic tool by Microsoft is a C++ package manager that typically builds libraries from source, ensuring better compatibility with your specific compiler and environment. This felt like a more robust approach for tricky dependencies like Boost.

My first attempts with Vcpkg were hopeful, but quickly led to new challenges. After cloning Vcpkg and bootstrapping it in PowerShell:

# In PowerShell
cd C:\dev
git clone https://github.com/microsoft/vcpkg.git
.\vcpkg\bootstrap-vcpkg.bat
.\vcpkg\vcpkg.exe install boost-beast:x64-mingw-ucrt

Vcpkg responded with:

error: Invalid triplet: x64-mingw-ucrt
Built-in Triplets: ...

This was baffling! x64-mingw-ucrt is the standard triplet for my environment. I tried git pull and bootstrap-vcpkg.bat again. "Already up to date," Git claimed. Yet, vcpkg still wouldn't recognize the triplet. A quick dir command even confirmed that the x64-mingw-ucrt.cmake file was missing from C:\dev\vcpkg\triplets\community after a fresh clone. It turns out, Vcpkg had changed how it managed these triplets, making my direct approach invalid.

Then, when trying other MinGW triplets (like x64-mingw-dynamic), Vcpkg threw another error:

error: in triplet x64-windows: Unable to find a valid Visual Studio instance
Could not locate a complete Visual Studio instance

Aargh! Why was it looking for Visual Studio? This was because Vcpkg, by default, assumes a "host triplet" (for its internal tools) of x64-windows (MSVC), which naturally requires Visual Studio. I needed to explicitly tell Vcpkg to use MinGW for everything.

💡 The Breakthrough: Forcing Vcpkg to Use MinGW

🧠 Key Insight:

To make Vcpkg work entirely with MinGW, you need to explicitly set both:

  • VCPKG_DEFAULT_TRIPLET

  • VCPKG_DEFAULT_HOST_TRIPLET

✅ Correct Way (PowerShell or cmd.exe):

$env:VCPKG_DEFAULT_TRIPLET = "x64-mingw-dynamic"
$env:VCPKG_DEFAULT_HOST_TRIPLET = "x64-mingw-dynamic"

# Now install Boost
.\vcpkg\vcpkg.exe install boost-beast

📦 Vcpkg will now:

  • Download Boost from source

  • Compile all required parts using MinGW

  • Store headers & libraries in:

    • C:\dev\vcpkg\installed\x64-mingw-dynamic\include

    • C:\dev\vcpkg\installed\x64-mingw-dynamic\lib

⌛ Be patient — it takes time!


🔗 Linking Vcpkg’s Boost with MSYS2 g++

Once installed, I returned to my MSYS2 UCRT64 shell to compile:

g++ -g genericMicroservice.cpp -o genericMicroservice.exe \
-I C:/dev/vcpkg/installed/x64-mingw-dynamic/include \
-L C:/dev/vcpkg/installed/x64-mingw-dynamic/debug/lib \
-L C:/dev/vcpkg/installed/x64-mingw-dynamic/lib \
-lboost_system -std=c++17

Still failed! Why?!

A look into lib folder revealed:

libboost_system-gcc15-mt-x64-1_88.dll.a

🤯 Suffixes! g++ doesn't auto-match suffixed names like -gcc15-mt-x64-1_88.

✅ Fix: Use Full Library Names in Linker Flags

g++ -g genericMicroservice.cpp -o genericMicroservice.exe \
-I C:/dev/vcpkg/installed/x64-mingw-dynamic/include \
-L C:/dev/vcpkg/installed/x64-mingw-dynamic/debug/lib \
-L C:/dev/vcpkg/installed/x64-mingw-dynamic/lib \
-lboost_system-gcc15-mt-x64-1_88 \
-lboost_date_time-gcc15-mt-x64-1_88 \
-lboost_context-gcc15-mt-x64-1_88 \
-lboost_container-gcc15-mt-x64-1_88 \
-lws2_32 -std=c++17

Compilation Success! 🎉

If your code needs more Boost modules (e.g., boost_thread), install and link them the same way.


✅ Conclusion

Installing Boost with MSYS2 and MinGW is not plug-and-play — but it is possible with the right tools and configurations.

🧭 Takeaways:

  • Vcpkg is powerful but needs proper configuration.

  • Understand how your compiler links libraries — names matter!

  • Stay curious, patient, and persistent.


0
Subscribe to my newsletter

Read articles from Jigyasha Sharma Sati directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Jigyasha Sharma Sati
Jigyasha Sharma Sati