Search code examples
c++ffmpegcross-compilingstatic-librariesmingw-w64

Can MinGW's static library be linked to MSVC


I use mingw-w64 on linux to cross compile the ffmpeg static library for windows with the following command:

./configure --arch=x86 --disable-doc --disable-ffplay --disable-ffprobe --disable-ffmpeg --prefix=/mnt/c/ffmpeg --enable-gpl --enable-nonfree --target-os=mingw32 --cross-prefix=i686-w64-mingw32- --pkg-config=pkg-config --disable-shared --enable-static

make -j16
make install

Then I got some .a files instead of .lib files. Can I directly link these files to MSVC? If not, what should I do next?


Solution

  • Even though you asked for a cross-compilation, here's how you do it natively on Windows. I'd rather do this than trying to use MinGW libraries with MSVC.

    This is adapted to MSYS2 from the official guide that uses MSYS1.

    • Install MSYS2 from https://www.msys2.org/
    • Update it using pacman -Syu. If it closes itself during update, restart and run pacman -Syu to finish the update.
    • Install things the ./configure script asks for: pacman -S make diffutils mingw-w64-ucrt-x86_64-yasm.
    • Close MSYS2, open VS developer command prompt, start MSYS2 inside of it using C:\msys64\msys2_shell.cmd -ucrt64 -full-path. This will add cl.exe to the PATH.
    • cd to FFmpeg source directory, ./configure --toolchain=msvc, make -j4, DESTDIR="$(realpath inst)" make install to install to ./inst.