ffmpeg icon indicating copy to clipboard operation
ffmpeg copied to clipboard

Windows Support

Open sqrt-negativeone opened this issue 1 year ago • 6 comments

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).

sqrt-negativeone avatar Jul 03 '23 12:07 sqrt-negativeone

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.

michaelshmitty avatar Aug 14 '23 19:08 michaelshmitty

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

michaelshmitty avatar Aug 14 '23 19:08 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.

michaelshmitty avatar Aug 16 '23 13:08 michaelshmitty

@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=

MyNameIsTrez avatar Oct 01 '23 16:10 MyNameIsTrez

@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?

michaelshmitty avatar Oct 03 '23 09:10 michaelshmitty

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.

andrewrk avatar Apr 08 '24 07:04 andrewrk