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

Static linking on Windows/MSVC/vcpkg? #513

Open
ziriax opened this issue May 18, 2021 · 0 comments
Open

Static linking on Windows/MSVC/vcpkg? #513

ziriax opened this issue May 18, 2021 · 0 comments

Comments

@ziriax
Copy link

ziriax commented May 18, 2021

I'm experimenting with static linking and vcpkg, and I get a lot of undefined linker errors when linking the libraries into my final DLL; it seems libheif is trying to reference libde265 dynamically even when building statically, like:

Creating library Release\eXpress.Imaging.Heif.Native.lib and object Release\eXpress.Imaging.Heif.Native.exp
heif.lib(heif_decoder_libde265.cc.obj) : error LNK2019: unresolved external symbol __imp_de265_get_version referenced in function "char const * __cdecl libde265_plugin_name(void)" (?libde265_plugin_name@@YAPEBDXZ)

I was able to fix this by modifying the libheif/CMakeLists.txt as follows:

--- a/libheif/CMakeLists.txt
+++ b/libheif/CMakeLists.txt
@@ -54,10 +54,17 @@ set_target_properties(heif
                           VERSION ${PROJECT_VERSION}
                           SOVERSION ${PROJECT_VERSION_MAJOR})

-target_compile_definitions(heif
-                           PUBLIC
-                               LIBHEIF_EXPORTS
-                               HAVE_VISIBILITY)
+if(BUILD_SHARED_LIBS)
+    target_compile_definitions(heif
+                            PUBLIC
+                                LIBHEIF_EXPORTS
+                                HAVE_VISIBILITY)
+else()
+    target_compile_definitions(heif
+                               PUBLIC
+                                   LIBHEIF_STATIC_BUILD
+                                   LIBDE265_STATIC_BUILD)
+endif()

 if(LIBDE265_FOUND)
     target_compile_definitions(heif PRIVATE HAVE_LIBDE265=1)

I'm not sure this is the correct way to do this.

And maybe the libde265 lib should be modified accordingly?

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

1 participant