Skip to content

Windows Support #6

Open
Open

Description

@sqrt-negativeone

Hey! I'm trying to build the project on windows but it fails with the following error

nasm.zig build-exe nasm ReleaseFast native: error: error(compilation): clang failed with stderr: In file included from C:\Users\sqrtminusone\AppData\Local\zig\p\122032bc8d97d857b7c2f71252da293e4f293a4ea0d162909fb0705ba17c40ae2a87\output\outieee.c:68:
C:\Users\sqrtminusone\AppData\Local\zig\p\122032bc8d97d857b7c2f71252da293e4f293a4ea0d162909fb0705ba17c40ae2a87\include/compiler.h:101:11: fatal error: 'endian.h' file not found

I'm using the zig 0.11, specifically zig-windows-x86_64-0.11.0-dev.3910+689f3163a.zip (the latest as of the time of writing).

Activity

  1. michaelshmitty commented on Aug 14, 2023

    @michaelshmitty

    I couldn't get it to build on MacOS (Ventura 13.5, Intel Mac using Zig 0.11.0 in a Nix shell) either with the same error. I did some digging and I believe the problem lies not within the ffmpeg tree, nor the build.zig file here. I believe it originates from the nasm dependency in build.zig.zon. It points to a fork by @andrewrk which may perhaps only build successfully on Linux?

    The error, fatal error: 'endian.h' file not found in compiler.h (a nasm source file) may be caused by incorrectly including endian.h for the platform(s). On Darwin endian.h must be included as machine/endian.h, I don't know about Windows. This is accounted for in the source code by the build flags HAVE_ENDIAN_H,HAVE_SYS_ENDIAN or HAVE_MACHINE_ENDIAN. I've forked @andrewrk 's nasm repo, tried fiddling with those variables in the build.zig there, but no effect.

    I did try manually messing with the compiler.h file in the zig cache (probably a very bad idea, having watched Andrew's talk on building from source :p, but hey at least I'm reporting the original issue amirite?) and that did seem to make the build process move beyond that point, but it resulted in another error down the line which I won't clutter this issue with.

  2. michaelshmitty commented on Aug 14, 2023

    @michaelshmitty

    For the record ffmpeg did build fine on Debian 12 x86_64 with Zig 0.11.0 and the build-essentials Debian package.

  3. michaelshmitty commented on Aug 16, 2023

    @michaelshmitty

    @sqrt-minus-one I've opened a PR (https://github.com/andrewrk/nasm/pull/2) to fix @andrewrk 's nasm fork build on MacOS. I probably have to do something similar for Windows. Would you mind telling me how you set up your environment on Windows to try to build this? I will try to replicate the build and the error and try to fix it.

    As I suspected it was the failure to build nasm that caused the build error in ffmpeg. Once I substituted my own fork of nasm into the build.zig.zon file here, it built ffmpeg just fine.

  4. MyNameIsTrez commented on Oct 1, 2023

    @MyNameIsTrez

    @michaelshmitty Hello, thanks for looking into it! :)

    I'm on Windows 10 and was getting fatal error: 'endian.h' file not found as well.

    After using this nasm fork of yours in ffmpeg's build.zig.zon, I am now getting error: static declaration of 'mempcpy' follows non-static declaration. You seem to have done something related to fixing MEMPCPY in this nasm PR of yours, but it unfortunately didn't prevent the error I'm getting right now. Do you maybe have a newer build.zig.zon URL I should be using instead of the one I linked, for nasm?

    Here is my zig libc, in case it's relevant:

    # 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.22000.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=E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\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.22000.0\ucrt\x64     
    
    # The directory that contains `vcruntime.lib`.
    # Only needed when targeting MSVC on Windows.
    msvc_lib_dir=E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\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.22000.0\um\x64
    
    # The directory that contains `crtbeginS.o` and `crtendS.o`
    # Only needed when targeting Haiku.
    gcc_dir=
    
  5. michaelshmitty commented on Oct 3, 2023

    @michaelshmitty

    @MyNameIsTrez Hi, no problem. Haven't look at this in a while because I haven't gotten any upstream reaction yet. I have not tried compiling on Windows, so no help there from me I'm afraid. All I did was add some more logic to what build flags get set depending on the environment to make it work on macos, because the original zon file assumed Linux. Maybe you can try the same process for Windows?
    Like on this line where it sets the HAVE_MEMCPY build flag, maybe you have to make it so that it also sets it if the os is Windows or something?

  6. changed the title [-]endian.h file not found[/-] [+]Windows Support[/+] on Apr 8, 2024
  7. andrewrk commented on Apr 8, 2024

    @andrewrk
    Collaborator

    Current status of windows support:

    andy@bark ~/d/ffmpeg (main)> zig-dev build -Dtarget=x86_64-windows
    install
    └─ install ffmpeg
       └─ zig build-lib ffmpeg Debug x86_64-windows 458 errors
    /home/andy/dev/ffmpeg/libavutil/thread.h:28:10: error: 'sys/prctl.h' file not found
    #include <sys/prctl.h>
             ^~~~~~~~~~~~~~
    /home/andy/dev/ffmpeg/libavcodec/aacdec_fixed.c:495:10: note: in file included from /home/andy/dev/ffmpeg/libavcodec/aacdec_fixed.c:495:
    #include "aacdec_template.c"
             ^
    /home/andy/dev/ffmpeg/libavcodec/aacdec_template.c:93:10: note: in file included from /home/andy/dev/ffmpeg/libavcodec/aacdec_template.c:93:
    #include "libavutil/thread.h"
             ^
    /home/andy/dev/ffmpeg/libavutil/thread.h:28:10: error: 'sys/prctl.h' file not found
    #include <sys/prctl.h>
             ^~~~~~~~~~~~~~
    /home/andy/dev/ffmpeg/libavcodec/aacdec.c:260:10: note: in file included from /home/andy/dev/ffmpeg/libavcodec/aacdec.c:260:
    #include "aacdec_template.c"
             ^
    /home/andy/dev/ffmpeg/libavcodec/aacdec_template.c:93:10: note: in file included from /home/andy/dev/ffmpeg/libavcodec/aacdec_template.c:93:
    #include "libavutil/thread.h"
             ^
    

    and many more errors. the build.zig script needs work.

  8. xiy commented on Jan 15, 2025

    @xiy

    Just dropping this in here as I'm currrently working on building this against my own Zig lib. The exact config lines in build.zig are here:

    https://github.com/allyourcodebase/ffmpeg/blob/a679ac6f297e5b98612734c78eb3bbdca9d994b1/build.zig#L427C1-L429C34

    I don't currently have a good Windows dev machine set up, but you could first try changing these config values to:

            .HAVE_PTHREADS = t.os.tag == .linux,
            .HAVE_OS2THREADS = false,
            .HAVE_W32THREADS = t.os.tag == .windows,

    This should handle the threading includes in thread.h. I can't promise this will work, but it's worth a go. There are likely other header macros you need to adjust so it might be worth looking up building ffmpeg on windows in general.

  9. by965738071 commented on Mar 16, 2026

    @by965738071

    Issue: NASM package fails to build on Windows

    问题描述

    使用 zig 0.16.0-dev.2905 在 Windows 上构建 ffmpeg 依赖时,nasm 包编译失败。

    错误信息

    error: 'endian.h' file not found
    # include <endian.h>
              ^~~~~~~~~~~
    
    error: 'sys/mman.h' file not found
    # include <sys/mman.h>
              ^~~~~~~~~~~~~
    
    error: redefinition of 'vsnprintf'
    int vsnprintf(char *str, size_t size, const char *format, va_list ap)
        ^
    ...previous definition is here
    

    根本原因

    nasm 包的 build.zig 在 Windows 上错误地设置了以下配置标志为 1(表示存在),但 Windows 并不提供这些 POSIX 头文件:

    • HAVE_ENDIAN_H = 1 - Windows 没有 endian.h
    • HAVE_MACHINE_ENDIAN_H = 1 - Windows 没有 machine/endian.h
    • HAVE_SYS_ENDIAN_H = 1 - Windows 没有 sys/endian.h
    • HAVE_MMAN = 1 - Windows 没有 sys/mman.h

    修复方案

    修改 nasm-2.16.1-5-J30Ed9pnXADeEiehXaWUd4iLEMPwLrIv42q9X7NUFs8O/build.zig,根据操作系统动态设置这些标志:

    // 将这些行:
    .HAVE_ENDIAN_H = 1,
    .HAVE_MACHINE_ENDIAN_H = 1,
    .HAVE_SYS_ENDIAN_H = 1,
    
    // 修改为:
    .HAVE_ENDIAN_H = have(t.os.tag != .windows),
    .HAVE_MACHINE_ENDIAN_H = have(t.os.tag != .windows),
    .HAVE_SYS_ENDIAN_H = have(t.os.tag != .windows),

    其中 have() 是已有的辅助函数:

    fn have(c: bool) ?c_int {
        return if (c) 1 else null;
    }

    测试环境

    • Zig version: 0.16.0-dev.2905+5d71e3051
    • OS: Windows (win32)
    • Target: x86_64-windows-msvc

    相关依赖

    此问题影响 ffmpeg 包的构建,因为 ffmpeg 依赖 nasm 来编译 x86 汇编优化代码。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions