haasn / libplacebo

Official mirror of libplacebo
http://libplacebo.org/
GNU Lesser General Public License v2.1
570 stars 73 forks source link

MingW64 compatible build with MSVC by changing convert.cc to convert.c #297

Closed ggarra13 closed 3 weeks ago

ggarra13 commented 4 weeks ago

MingW64 compilation on Windows would work as a DLL, but it would not allow linking libplacebo with MSVC due to the use of the libstdc++ in at least one file: convert.cc.

This PR adds a C convert.c file with C functions instead of C++ ones, which can be linked safely between compilers.

It is not as efficient as the C++ implementation but it allows Windows interoperatibility.

kasper93 commented 3 weeks ago

So why do you want to use mingw on Windows when you are using it with MSVC? Your are creating your own problems.

Also it works fine as DLL, what you probably mean is static linking and for that you should always use the same compiler, regardless of anything else.

ggarra13 commented 3 weeks ago

So why do you want to use mingw on Windows when you are using it with MSVC? Your are creating your own problems.

Windows compilation under MSVC does not work as libplacebo uses atomics which are not supported in MSVC 2019/2022. If you know how to make it compile under MSVC2022 community edition, please post the command lines I should use.

Also it works fine as DLL, what you probably mean is static linking and for that you should always use the same compiler, regardless of anything else.

In a perfect world, I would.

But as I said MSVC, as far as I could try, cannot compile libplacebo's source code. It does get compiled fine with MingW64 with no problem as a DLL where the function signatures are the same as in the MSVC compiler, except for C++ std:: which is limited to just one file (convert.cc).

If you compile a static library with MingW64 also the function signatures don't match.

kasper93 commented 3 weeks ago

Windows compilation under MSVC does not work as libplacebo uses atomics which are not supported in MSVC 2019/2022. If you know how to make it compile under MSVC2022 community edition, please post the command lines I should use.

clang works fine for libplacebo build without mingw. I don't think it is integrated in libplacebo CI, but I build it on mpv CI. See https://github.com/mpv-player/mpv/actions/runs/11615188866/job/32345146580 and https://github.com/mpv-player/mpv/blob/master/ci/build-win32.ps1. Basically if you run VS developer console and set CC=clang and CXX=clang++, meson will build without a hiccup.

It does get compiled fine with MingW64 with no problem as a DLL where the function signatures are the same as in the MSVC compiler, except for C++ std:: which is limited to just one file (convert.cc).

But if you build and link agains libstdc++ you should just use it along with your libplacebo.dll. DLLs in Windows are fully standalone and unlike on *nix they don't mix symbols with "parent" application, so I don't see where is the problem. convert.cc is not user facing API.

ggarra13 commented 3 weeks ago

clang works fine for libplacebo build without mingw. I don't think it is integrated in libplacebo CI, but I build it on mpv CI. See https://github.com/mpv-player/mpv/actions/runs/11615188866/job/32345146580 and https://github.com/mpv-player/mpv/blob/master/ci/build-win32.ps1. Basically if you run VS developer console and set CC=clang and CXX=clang++, meson will build without a hiccup.

Oh... sweet! I just learnt something new, as MSVC's shipped clang is ABI compatible with MSVC. I'll test it next week to see if I can change to using clang in my Github Action.