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

All library functions being exported with BUILD_SHARED_LIBS=Off on MSVC #902

Open
zenden2k opened this issue Jun 17, 2023 · 3 comments
Open

Comments

@zenden2k
Copy link

zenden2k commented Jun 17, 2023

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
@rgpublic
Copy link

rgpublic commented Aug 7, 2023

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
Copy link

Any updates here perhaps? 👀

@rgpublic
Copy link

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.

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

2 participants