ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.94k stars 2.55k forks source link

zig build fails with many errors in any-windows-any #21996

Open circle67 opened 2 hours ago

circle67 commented 2 hours ago

Zig Version

0.13.0

Steps to Reproduce and Observed Behavior

When attempting to build I get a heap of errors (21) with the following build script:

const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{ .preferred_optimize_mode = .ReleaseFast });

    const raylib = b.dependency("raylib", .{
        .target = target,
        .optimize = optimize,
    });

    const exe = b.addExecutable(.{
        .name = "name",
        .target = target,
        .optimize = optimize,
    });

    exe.addIncludePath(raylib.path("src"));
    exe.addIncludePath(b.path("external/sqlite/src"));

    exe.addCSourceFiles(.{
        .root = b.path("src"),
        .files = &.{
            "main.cpp",
            // etc.
        },
    });

    exe.linkLibCpp();

    b.installArtifact(exe);
}

As far as I know, the errors come exclusively from my code (not Raylib or SQLite). I get many "unknown type name 'x'" and "no matching function for call to 'x'" errors:

Zig\lib\libc\include\any-windows-any/vadefs.h:31:11: error: unknown type name '__gnuc_va_list'
  typedef __gnuc_va_list va_list;
          ^
example1.cpp:3:10: note: in file included from example1.cpp:3:
#include <cctype>
         ^
Zig\lib\libcxx\include/cctype:40:10: note: in file included from Zig\lib\libcxx\include/cctype:40:
#include <ctype.h>
         ^
Zig\lib\libcxx\include/ctype.h:39:17: note: in file included from Zig\lib\libcxx\include/ctype.h:39:
#  include_next <ctype.h>
                ^
Zig\lib\libc\include\any-windows-any/ctype.h:9:10: note: in file included from Zig\lib\libc\include\any-windows-any/ctype.h:9:
#include <crtdefs.h>
         ^
Zig\lib\libc\include\any-windows-any/crtdefs.h:10:10: note: in file included from Zig\lib\libc\include\any-windows-any/crtdefs.h:10:
#include <corecrt.h>
         ^
Zig\lib\libc\include\any-windows-any/corecrt.h:10:10: note: in file included from Zig\lib\libc\include\any-windows-any/corecrt.h:10:
#include <_mingw.h>
         ^
Zig\lib\libc\include\any-windows-any/_mingw.h:282:10: note: in file included from Zig\lib\libc\include\any-windows-any/_mingw.h:282:
#include <vadefs.h> /* other headers depend on this include */
         ^
Zig\lib\include/vadefs.h:12:15: note: in file included from Zig\lib\include/vadefs.h:12:
#include_next <vadefs.h>
Zig\lib\libc\include\any-windows-any/wchar.h:663:13: error: no matching function for call to '__stdio_common_vfwscanf'
    __ret = __stdio_common_vfwscanf(_CRT_INTERNAL_LOCAL_SCANF_OPTIONS, _File, _Format, NULL, __ap);
            ^
main.cpp:3:10: note: in file included from main.cpp:3:
#include "example2.h"
         ^
example2.h:4:10: note: in file included from example2.h:4:
#include <vector>
         ^
Zig\lib\libcxx\include/vector:314:10: note: in file included from Zig\lib\libcxx\include/vector:314:
#include <__algorithm/remove.h>
         ^
Zig\lib\libcxx\include/__algorithm/remove.h:12:10: note: in file included from Zig\lib\libcxx\include/__algorithm/remove.h:12:
#include <__algorithm/find.h>
         ^
Zig\lib\libcxx\include/__algorithm/find.h:31:12: note: in file included from Zig\lib\libcxx\include/__algorithm/find.h:31:
#  include <cwchar>
           ^
Zig\lib\libcxx\include/cwchar:114:10: note: in file included from Zig\lib\libcxx\include/cwchar:114:
#include <wchar.h>
         ^
Zig\lib\libcxx\include/wchar.h:127:19: note: in file included from Zig\lib\libcxx\include/wchar.h:127:
#    include_next <wchar.h>
                  ^
Zig\lib\libc\include\any-windows-any/wchar.h:520:15: note: candidate function not viable: no known conversion from '__builtin_va_list' to 'va_list' (aka 'int') for 5th argument; dereference the argument with *
  int __cdecl __stdio_common_vfwscanf(unsigned __int64 options, FILE *file, const wchar_t *format, _locale_t locale, va_list valist);
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I have another project in C++ using the Zig build system that builds just fine, so this could all be some massive oversight in my build script or something wrong in my code 🤷

Expected Behavior

I expected it to build.

alexrp commented 2 hours ago

You haven't specified what platform you're building on and what your zig build invocation looks like.

kcbanner commented 2 hours ago

If you are building using the -msvc ABI, then you can't use exe.linkLibCpp() - it fails to compiled under the msvc ABI.

You can conditionally call that function:

    if (target.result.abi != .msvc) {
        exe.linkLibCpp();

The msvc ABI behaviour is to automatically link the system supplied C++ standard library when it's used (https://learn.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=msvc-170#c-standard-library-stl-lib-files)