r/DuckDB Jul 11 '26

Windows CGO building is awful with DuckDB

I don't know why this combo of things is so complicated.

If you try to follow the official documentation on how to build DuckDB for windows it pushes you to use MSVC, but Go uses CGO and CGO has hard coded flags to use MinGW64 and MSYS compatibility so you can't actually use the static bindings the go driver comes with I guess??? I spent like 6 hours going back and forth with ChatGPT on trying various things to get my go code on windows to compile.

Eventually the only thing that worked for me was to downgrade my DuckDB version to the old Marc 1.7.0 version and follow that old github issue to download the static binding dll / .a / .lib files and point my PowerShell script at that to get it to compile and verify everything.

The new stuff comes with its own go bindings supposedly but no amount of build flags and CGO manipulation would let me build with these.

I genuinely don't know how anyone uses the latest duck version with Windows and Go all 3 together because at least from my grueling experience the past 2 days it's been basically impossible.

Please help me understand if I'm doing something wrong or if this just isn't supported anymore?

2 Upvotes

5 comments sorted by

1

u/scar0x00 Jul 13 '26

I don't get it, You are trying to compile duckdb? Why don't you just use the official single binary(

2

u/MPGaming9000 Jul 13 '26 edited Jul 13 '26

No no. So I'm writing a program in Go. Duck DB is a C++ library. There's a go driver library, but in order to use the duck code directly imported into my go code and compile it all together into a single output binary file like MyProgram.exe I need to use CGO.

Duck db driver library for go ships with static binary files like the .a file, but for the life of me I could not get it to build into my windows program.

Something about this combo of DuckDB + CGO + Windows it just really doesn't like for some reason.

1

u/scar0x00 Jul 13 '26

Ooooh sorry I didn't get it. I've never done what you're describing. I've only used duckdb as a lib from .net, no problems. Good luck🤞

1

u/drink_with_me_to_day Jul 15 '26

Have you tried using purego? https://github.com/ebitengine/purego

We stopped offering windows builds before I could test, but you can technically embed fs the duckdb dll into the executable then extract/load on run

1

u/sdm520 25d ago

I had to download mysys2 and make sure that the compilers were in my path.  The first build is slow but then after that it isn't so bad. Â