Skip to content

Headers not found on msvc abi #9093

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

Closed
Sirius902 opened this issue Jun 12, 2021 · 2 comments
Closed

Headers not found on msvc abi #9093

Sirius902 opened this issue Jun 12, 2021 · 2 comments
Labels
bug Observed behavior contradicts documented or intended behavior os-windows
Milestone

Comments

@Sirius902
Copy link

Sirius902 commented Jun 12, 2021

With the following program on Windows (I have exe.linkLibC(); in the build script)

const print = @import("std").debug.print;
const c = @cImport(@cInclude("stdio.h"));

pub fn main() void {
    print("{}\n", .{c.EOF});
}

It prints -1 as output with -Dtarget=native-native-gnu but on -Dtarget=native-native-msvc I get the following compiler error:

.\src\main.zig:2:11: error: C import failed
const c = @cImport(@cInclude("stdio.h"));
          ^
.\zig-cache\o\554df7d82185a847c43862003dfc7d3c\cimport.h:1:10: note: 'stdio.h' file not found
#include <stdio.h>
         ^
.\src\main.zig:5:21: note: referenced here
    print("{}\n", .{c.EOF});
                    ^

Here is my output from zig libc:

# The directory that contains `stdlib.h`.
# On POSIX-like systems, include directories be found with: `cc -E -Wp,-v -xc /dev/null`
include_dir=C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt

# The system-specific include directory. May be the same as `include_dir`.
# On Windows it's the directory that includes `vcruntime.h`.
# On POSIX it's the directory that includes `sys/errno.h`.
sys_include_dir=C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30037\include

# The directory that contains `crt1.o` or `crt2.o`.
# On POSIX, can be found with `cc -print-file-name=crt1.o`.
# Not needed when targeting MacOS.
crt_dir=C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\ucrt\x64

# The directory that contains `vcruntime.lib`.
# Only needed when targeting MSVC on Windows.
msvc_lib_dir=C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30037\lib\x64\

# The directory that contains `kernel32.lib`.
# Only needed when targeting MSVC on Windows.
kernel32_lib_dir=C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x64

# The directory that contains `crtbeginS.o` and `crtendS.o`
# Only needed when targeting Haiku.
gcc_dir=

Edit: I'd like to add that this used to work on older Zig versions. Currently I'm on zig-windows-x86_64-0.9.0-dev.117+0d022eb1d.

@Sirius902
Copy link
Author

Sirius902 commented Jun 23, 2021

I would like to add that directly running zig run -lc -Dtarget=native-native-msvc src/main.zig instead of invoking the build script does not have this problem. I checked to make sure when running the build script (with zig build run) and -lc is passed to zig build-exe but even despite that it can't find the headers.

Now on 0.9.0-dev.250+c6844072c.

@andrewrk andrewrk added this to the 0.8.1 milestone Jun 23, 2021
@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior os-windows labels Jun 23, 2021
@Sirius902
Copy link
Author

Fixed as of 2d85574.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior os-windows
Projects
None yet
Development

No branches or pull requests

2 participants