-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
build failure for c sources that include windows.h when targetting msvc abi #19805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
To my knowledge, cross-compiling for the MSVC ABI from non-Windows is not supported. You need to use the GNU ABI instead. If you do that, you also don't need to mess with include paths like this. |
switching to const std = @import("std");
pub fn build(b: *std.Build) !void {
const exe = b.addExecutable(.{
.name = "test",
.target = .{ .cpu_arch = .x86, .os_tag = .windows, .abi = .gnu },
.optimize = .ReleaseSmall,
});
exe.addCSourceFile(.{ .file = .{ .path = "test.c" }, .flags = &.{"-w"} });
const windows_include_dir = try std.fs.path.resolve(
b.allocator,
&.{ std.fs.path.dirname(b.zig_exe).?, "..", "lib/zig/libc/include/any-windows-any" },
);
exe.addIncludePath(.{ .path = windows_include_dir });
exe.linkLibC();
b.installArtifact(exe);
} final so it seems the issue is now reduced to msvc abi (with a side of include path unpleasantness). |
does building it like this incur an incompatibility with windows systems that have no knowledge of mingw, by the way? |
You can remove // is this really the best way to do it :(
const windows_include_dir = try std.fs.path.resolve(
b.allocator,
&.{ std.fs.path.dirname(b.zig_exe).?, "..", "lib/zig/libc/include/any-windows-any" },
); now that you have const std = @import("std");
pub fn build(b: *std.Build) !void {
const dll = b.addSharedLibrary(.{
.name = "test",
.target = .{ .cpu_arch = .x86, .os_tag = .windows, .abi = .gnu },
.optimize = .ReleaseSmall,
});
dll.addCSourceFile(.{ .file = .{ .path = "test.c" }, .flags = &.{"-w"} });
dll.linkLibC();
b.installArtifact(dll);
} In the future, questions like this should be directed towards one of the community spaces first. |
oops you're right! I could swear I tried nevertheless, the two open issues I found on my initial search (#11926, #6003) seemed marginally related and rather old. neither reported errors similar to the ones I had here. so I figured it'd be worth reporting as an issue. the original issue stands: a build failure when targeting msvc abi and including windows.h @squeek502 if that's not applicable and deserves the wontfix for some reason, please let me know |
Targeting the For example, this would succeed on Windows if you have the MSVC/SDK includes installed: const std = @import("std");
pub fn build(b: *std.Build) !void {
const dll = b.addSharedLibrary(.{
.name = "test",
.target = .{ .cpu_arch = .x86, .os_tag = .windows, .abi = .msvc },
.optimize = .ReleaseSmall,
});
dll.addCSourceFile(.{ .file = .{ .path = "test.c" }, .flags = &.{"-w"} });
dll.linkLibC();
b.installArtifact(dll);
} The most relevant issue is probably #6565 |
@squeek502 we might be able to leverage win32metadata/zigwin32 to generate includes compatible with MSVC headers...? |
I think headers are just one component, would also need |
If you're talking about the link lib files, those are trivially easy to generate. Much easier than the header files. |
in the interim, a more informative error message when using the msvc abi in target may be worth having I think (with the exception of native-native-msvc, already indicating we're using the system sdk) |
Uh oh!
There was an error while loading. Please reload this page.
Zig Version
0.11.0
Steps to Reproduce and Observed Behavior
fails in these locations under
libc/include/any-windows-any
:repro:
Expected Behavior
it builds
The text was updated successfully, but these errors were encountered: