I'm trying to include libheif into my project using cmake. Libheif is more complicated than what I've worked with before because it requires you externally build and include libde265.
Attempt #1:
I have used vcpkg to export pre-built binary packages, this creates a directory called libheif which includes everything here:
+---bin
| heif.dll
| libde265.dll
| libx265.dll
| libx265.pdb
|
+---debug
| +---bin
| | heif.dll
| | libde265.dll
| | libx265.dll
| | libx265.pdb
| |
| ---lib
| | heif.lib
| | libde265.lib
| | libx265.lib
| | x265-static.lib
| |
| ---pkgconfig
| libheif.pc
| x265.pc
|
+---include
| | x265.h
| | x265_config.h
| |
| +---libde265
| | de265.h
| |
| ---libheif
| heif.h
|
+---lib
| | heif.lib
| | libde265.lib
| | libx265.lib
| | x265-static.lib
| |
| ---pkgconfig
| libheif.pc
| x265.pc
|
+---share
| +---libde265
| | copyright
| | libde265Config-debug.cmake
| | libde265Config-release.cmake
| | libde265Config.cmake
| | libde265ConfigVersion.cmake
| | vcpkg_abi_info.txt
| |
| +---libheif
| | | copyright
| | | libheif-config-debug.cmake
| | | libheif-config-release.cmake
| | | libheif-config-version.cmake
| | | libheif-config.cmake
| | | vcpkg_abi_info.txt
| | |
| | ---.vs
| | ProjectSettings.json
| | slnx.sqlite
| |
| ---x265
| copyright
| vcpkg_abi_info.txt
|
---tools
+---libde265
| dec265.exe
| enc265.exe
| libde265.dll
|
---x265
x265.exe
(There were more headers, I removed them because one illustrates the point) I put folder libheif
in my external folder in my project. Then in CMakeLists.txt
I have tried using
target_link_libraries(my_project ${CMAKE_SOURCE_DIR}/external/libheif/lib/heif)
that then fails looking for heif.obj
file that is not there. It does find the dlls though.
After that failed, I tried again, this time using the .cmake files in the share directory:
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/external/libheif/share/libheif)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/external/libheif/share/libde265)
include(libheif-config)
include(libde265Config)
This I get unresolved external symbol when trying to use anything in libheif.
Attempt #2:
I tried including libeheif by adding it as a submodule git submodule add https://github.com/strukturag/libheif.git external/libheif
and then in CMakeLists.txt
I added:
include_directories(external/libheif/include)
include_directories(external/libheif/include/libheif)
include_directories(external/libheif/include/libde265)
add_subdirectory(external/libheif)
target_link_libraries(my_project libheif)
This results in unresolved external symbols whenever I try to use anything in the libheif library.
Other information
- The only successful thing I have been able to do is include the headers directory so intellisence recognizes when I
#include <heif.h>
- I have looked all over on how to include dll and libraries, but all the results either need me to use the cmake GUI, which I am not sure I can because I'm working on this project with other people and I want to make sure it works on their computer without having to use the cmake GUI.
- Same with just using vcpkg to include it, I dont want my teammates to have to use it as well, I need to just use CMakeLists.txt
- This tutorial would be helpful but the generate stuff is above my head and I couldnt find what it meant by generate. It might be a rabbit hole I loose a day over.
- I am working on Windows 10, I will eventually need to make it so it can build on OSX but I'm just trying to get it to work on windows for now.
I am trying to understand why each of these approaches failed. I would rather go down the path of attempt #2 because I feel like that is better for down the road when I need to make it compile for mac as well. Thank you.
question from:
https://stackoverflow.com/questions/65876270/include-libheif-as-an-external-dependency-into-project-using-cmake 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…