Linking to cURL on Windows

I’m trying to link to cURL on a Windows host. So far my build.zig looks like this:

    exe.addIncludePath("curl/include");

    exe.linkLibC();
    exe.linkSystemLibrary("bcrypt");
    exe.linkSystemLibrary("crypt32");
    exe.linkSystemLibrary("ws2_32");
    exe.linkSystemLibrary("wldap32");

    exe.addObjectFile("curl/lib/libbrotlicommon.a");
    exe.addObjectFile("curl/lib/libbrotlidec.a");
    exe.addObjectFile("curl/lib/libcrypto.a");
    exe.addObjectFile("curl/lib/libcurl.a");
    exe.addObjectFile("curl/lib/libgsasl.a");
    exe.addObjectFile("curl/lib/libnghttp2.a");
    exe.addObjectFile("curl/lib/libnghttp3.a");
    exe.addObjectFile("curl/lib/libngtcp2_crypto_openssl.a");
    exe.addObjectFile("curl/lib/libngtcp2.a");
    exe.addObjectFile("curl/lib/libssh2.a");
    exe.addObjectFile("curl/lib/libssl.a");
    exe.addObjectFile("curl/lib/libz.a");
    exe.addObjectFile("curl/lib/libzstd.a");

However I’m still missing some symbols:

lld-link: error: undefined symbol: __declspec(dllimport) __sys_nerr
>>> referenced by libcurl.a(strerror.o):(Curl_strerror)

lld-link: error: undefined symbol: __declspec(dllimport) __sys_errlist
>>> referenced by libcurl.a(strerror.o):(Curl_strerror)

lld-link: error: undefined symbol: WspiapiGetNameInfo
>>> referenced by libcrypto.a(libcrypto-lib-bio_addr.obj):(addr_strings)

lld-link: error: undefined symbol: gai_strerrorA
>>> referenced by libcrypto.a(libcrypto-lib-bio_addr.obj):(addr_strings)
>>> referenced by libcrypto.a(libcrypto-lib-bio_addr.obj):(BIO_lookup_ex)

lld-link: error: undefined symbol: WspiapiFreeAddrInfo
>>> referenced by libcrypto.a(libcrypto-lib-bio_addr.obj):(BIO_ADDRINFO_free)

lld-link: error: undefined symbol: WspiapiGetAddrInfo
>>> referenced by libcrypto.a(libcrypto-lib-bio_addr.obj):(BIO_lookup_ex)
error: FileNotFound

Any idea?

I haven’t tried, maybe this example helps: Code Examples ⚡ Zig Programming Language
You could either try starting from that example, or invoke the pkg-config --cflags libcurl manually, to find out what flags you need on your system and port those to the equivalent build.zig code.

1 Like