Skip to content
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

libheif 1.14.0 fails to build for MinGW #713

Closed
kmilos opened this issue Nov 16, 2022 · 13 comments
Closed

libheif 1.14.0 fails to build for MinGW #713

kmilos opened this issue Nov 16, 2022 · 13 comments

Comments

@kmilos
Copy link
Contributor

kmilos commented Nov 16, 2022

Up until 1.14.0, the build worked pretty much out of the box, but now it fails, see the log here: https://github.com/msys2/MINGW-packages/actions/runs/3473745090/jobs/5806121808#step:11:386

Major: missing symbols when linking the new libheif-svtenc.dll

Linking CXX shared module libheif\plugins\libheif-svtenc.dll
FAILED: libheif/plugins/libheif-svtenc.dll
cmd.exe /C "cd . && C:\msys64\ucrt64\bin\g++.exe -march=nocona -msahf -mtune=generic -O2 -pipe -DX26
5_API_IMPORTS       -O3 -DNDEBUG  -pipe -shared -o libheif\plugins\libheif-svtenc.dll -Wl,--major-im
age-version,1,--minor-image-version,14 libheif/plugins/CMakeFiles/heif-svtenc.dir/heif_encoder_svt.c
c.obj libheif/plugins/CMakeFiles/heif-svtenc.dir/__/heif_plugin.cc.obj  C:/msys64/ucrt64/lib/libSvtA
v1Enc.dll.a  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -
ladvapi32 && cd ."
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 libheif/plugins/CMakeFiles/heif-svtenc.dir/heif_encoder_svt.cc.obj:heif_encoder_svt.cc:(.text+0xb5a
): undefined reference to `heif_image_get_width'

... and many more

Minor: unused variable (-Werror=unused-variable is default on MSYS2)

Building CXX object libheif/plugins/CMakeFiles/heif-svtenc.dir/heif_encoder_svt.cc.obj
FAILED: libheif/plugins/CMakeFiles/heif-svtenc.dir/heif_encoder_svt.cc.obj
C:\msys64\ucrt64\bin\g++.exe -DHAVE_UNISTD_H -DHAVE_VISIBILITY -DLIBHEIF_EXPORTS -DPLUGIN_SvtEnc=1 -
Dheif_svtenc_EXPORTS -IC:/msys64/home/kmilos/MINGW-packages/mingw-w64-libheif/src/libheif-1.14.0 -
IC:/msys64/home/kmilos/MINGW-packages/mingw-w64-libheif/src/build-UCRT64 -march=nocona -msahf -mtu
ne=generic -O2 -pipe -DX265_API_IMPORTS       -O3 -DNDEBUG -fvisibility=hidden -fno-keep-inline-dlle
xport   -Wall -Werror -Wsign-compare -Wconversion -Wno-sign-conversion -Wno-error=conversion -Wno-er
ror=unused-parameter -Wno-error=deprecated-declarations -std=c++11 -MD -MT libheif/plugins/CMakeFile
s/heif-svtenc.dir/heif_encoder_svt.cc.obj -MF libheif\plugins\CMakeFiles\heif-svtenc.dir\heif_encode
r_svt.cc.obj.d -o libheif/plugins/CMakeFiles/heif-svtenc.dir/heif_encoder_svt.cc.obj -c C:/msys64/ho
me/kmilos/MINGW-packages/mingw-w64-libheif/src/libheif-1.14.0/libheif/plugins/heif_encoder_svt.cc
C:/msys64/home/kmilos/MINGW-packages/mingw-w64-libheif/src/libheif-1.14.0/libheif/plugins/heif_enc
oder_svt.cc: In function 'int int_log2(int)':
C:/msys64/home/kmilos/MINGW-packages/mingw-w64-libheif/src/libheif-1.14.0/libheif/plugins/heif_enc
oder_svt.cc:99:7: error: unused variable 'input_value' [-Werror=unused-variable]
   99 |   int input_value = pow2_value;
      |       ^~~~~~~~~~~
cc1plus.exe: all warnings being treated as errors
@farindk
Copy link
Contributor

farindk commented Nov 16, 2022

I had a look at your log output. In this line:

cmd.exe /C "cd . && D:\M\msys64\ucrt64\bin\g++.exe -march=nocona -msahf -mtune=generic -O2 -pipe -DX265_API_IMPORTS      -O3 -DNDEBUG  -pipe -shared -o libheif\plugins\libheif-rav1e.dll -Wl,--major-image-version,1,--minor-image-version,14 libheif/plugins/CMakeFiles/heif-rav1e.dir/heif_encoder_rav1e.cc.obj libheif/plugins/CMakeFiles/heif-rav1e.dir/__/box.cc.obj libheif/plugins/CMakeFiles/heif-rav1e.dir/__/error.cc.obj libheif/plugins/CMakeFiles/heif-rav1e.dir/__/heif_plugin.cc.obj  D:/M/msys64/ucrt64/lib/librav1e.dll.a  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."

I find this path: libheif/plugins/CMakeFiles/heif-rav1e.dir/__/box.cc.obj
It seems that the parent directory '..' has been replaced by '__'.
Do you have any idea why that may be the case of whether it is only a display issue?

@kmilos
Copy link
Contributor Author

kmilos commented Nov 16, 2022

This is not an issue, those are just temporary paths crated by the build system...

@kmilos
Copy link
Contributor Author

kmilos commented Nov 16, 2022

I had to add

set(SvtEnc_extra_plugin_sources ../bitstream.cc ../box.cc ../error.cc ../heif.cc ../heif_avif.cc ../heif_colorconversion.cc ../heif_context.cc ../heif_file.cc ../heif_hevc.cc ../heif_image.cc ../heif_plugin_registry.cc ../nclx.cc)

in order to get it to link all the symbols. Now I'm running into the same problem w/ the rav1e plugin...

It seems since switching SVT-AV1 and rav1e to plugins, there are quite a few more sources that need to be added.

Or one has to also build a static libheif (the default on MSYS2 is shared), and link that in for the plugins.

@farindk
Copy link
Contributor

farindk commented Nov 16, 2022

Ok, but I still think that it might be a problem that I access sources from a parent directory with '..' in the plugins/CMakeLists.txt
Maybe that is not allowed and I should reference the parent directory in a different way.

@kmilos
Copy link
Contributor Author

kmilos commented Nov 16, 2022

As mentioned, that's not a problem here, just CMake internals...

@mmuetzel
Copy link

It seems that the parent directory '..' has been replaced by '__'.
Do you have any idea why that may be the case of whether it is only a display issue?

Afaict, that is how cmake works. And iiuc, the error message is not about the object file not being found.
I'd guess this could be symbol visibility issue. Maybe, those symbols need to be attributed with LIBHEIF_API in the compilation unit where they are defined.

@kmilos
Copy link
Contributor Author

kmilos commented Nov 16, 2022

Maybe, those symbols need to be attributed with LIBHEIF_API in the compilation unit where they are defined.

Nope, the units are just plain missing (if the intention is to build in statically), or shared libheif is not being linked to.

@farindk
Copy link
Contributor

farindk commented Nov 16, 2022

It's because these codecs are now compiled as independent plugins. But since they still share some code with libheif, some of the libheif core code also has to be included when compiling the plugin DLL.

BTW: dynamic plugins are not yet supported on Windows. Thus, it doesn't make much sense to compile them as DLLs.
You might want to switch off all WITH_*_PLUGIN variables. Some are enabled by default (svt and rav1e).

@kmilos
Copy link
Contributor Author

kmilos commented Nov 16, 2022

BTW: dynamic plugins are not yet supported on Windows. Thus, it doesn't make much sense to compile them as DLLs.
You might want to switch off all WITH_*_PLUGIN variables. Some are enabled by default (svt and rav1e).

Can you please do platform detection and set appropriate defaults then? Or have them as opt-in rather than opt-out if they're not working everywhere? Update the release notes?

So RAV1E, which was available as on option until 1.13.0, has to now be removed on Windows?

@farindk
Copy link
Contributor

farindk commented Nov 16, 2022

rav1e still works, but has to be compiled into libheif as before.
I'll look into setting suitable defaults for Windows...

@kmilos
Copy link
Contributor Author

kmilos commented Nov 16, 2022

rav1e still works, but has to be compiled into libheif as before

Ok, -DWITH_RAV1E_PLUGIN=OFF -DWITH_SvtEnc_PLUGIN=OFF works, thanks.

@farindk
Copy link
Contributor

farindk commented Nov 16, 2022

With the above change, it should now compile with the default settings.
You may still want to set `WITH_SvtEnc=OFF' to avoid adding more dependencies than before.

@kmilos
Copy link
Contributor Author

kmilos commented Nov 16, 2022

Thanks, confirmed working as well, just perhaps missing some optional polish, as still says early:

-- Found SvtEnc
-- Found SvtEnc: C:/msys64/ucrt64/include
Svt-av1 (AVIF encoder): found (plugin)
-- Found RAV1E
-- Found RAV1E: C:/msys64/ucrt64/include/rav1e
Rav1e (AVIF encoder): found (plugin)

but then, correctly later:

Compiling 'svtenc' as built-in backend
Compiling 'rav1e' as built-in backend

I'll close anyway, with the unused variable PR above and this commit, it now builds cleanly in all MSYS2 environments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants