libheif
libheif copied to clipboard
All library functions being exported with BUILD_SHARED_LIBS=Off on MSVC
When compiling static library v1.16.2 with CMake and Visual Studio 2019, all the libheif functions are being exported. This causes all consumers of this library to have a large list of libheif functions exported from resulting executables.
I see that setting the BUILD_SHARED_LIBS=Off option does not result in a macro definition LIBHEIF_STATIC_BUILD .
Setting LIBHEIF_STATIC_BUILD manually causes compiler errors.
#if defined(_MSC_VER) && !defined(LIBHEIF_STATIC_BUILD)
#ifdef LIBHEIF_EXPORTS
#define LIBHEIF_API __declspec(dllexport)
#else
#define LIBHEIF_API __declspec(dllimport)
#endif
#elif defined(HAVE_VISIBILITY) && HAVE_VISIBILITY
#ifdef LIBHEIF_EXPORTS
#define LIBHEIF_API __attribute__((__visibility__("default")))
#else
#define LIBHEIF_API
#endif
#else
#define LIBHEIF_API
#endif
I'm not sure but might be related... I'm also trying to compile libheif statically:
cmake -DBUILD_SHARED_LIBS=OFF --preset=release-noplugins ..
Initially, it seems to work (no error) and I get a .a file. But when I try to compile ImageMagick it fails (various missing references). The last version I could compile a static IM binary with is 1.15.2 - I guess due to the autotools still existing there. Sth. seems to be wrong with the CMake static builds...
Any updates here perhaps? :eyes:
Just for the record: I've finally gotten to the bottom of this and could for the first successfully compile ImageMagick with a more recent CMake-based libheif (1.19.5). The solution is to add aom and de265 manually to the linker when compiling ImageMagick like so:
export LIBS='-laom -lde265'
Interestingly, this was never necessary with the old autotools-based libheif. This could of course also be the solution for other things you might want to compile with a static libheif.
Duplicates #513.