libheif icon indicating copy to clipboard operation
libheif copied to clipboard

All library functions being exported with BUILD_SHARED_LIBS=Off on MSVC

Open zenden2k opened this issue 2 years ago • 3 comments

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

zenden2k avatar Jun 17 '23 18:06 zenden2k

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

rgpublic avatar Aug 07 '23 14:08 rgpublic

Any updates here perhaps? :eyes:

rgpublic avatar Nov 22 '24 17:11 rgpublic

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.

rgpublic avatar Nov 27 '24 18:11 rgpublic

Duplicates #513.

dg0yt avatar Jul 11 '25 18:07 dg0yt