Issues found when trying to get OIIO working as a static library on Windows #3611
DominikGrabiec
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I wanted a public place to write down and discuss the list of issues that I've found while trying to get OIIO building as a static library on Windows and linking it into another executable / dynamic library. I've got fixes for some of these issues but I'm not sure if any single change is the right way to go about it given the history of the project and other platforms and configurations it's used in.
Some advice, guidance, and hints would be appreciated.
I've used the guide that @aras-p has made but I've installed the dependencies with
vcpkgto the global location, and reduced the initial CMake command to:cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static-md -DCMAKE_TOOLCHAIN_FILE=E:\vcpkg\scripts\buildsystems\vcpkg.cmake -DBUILD_SHARED_LIBS=OFF -DLINKSTATIC=ON -DVERBOSE=ON -DBUILD_DOCS=OFF -DINSTALL_DOCS=OFF -DBUILD_TESTING=OFF -DOIIO_BUILD_TOOLS=OFF -DOIIO_BUILD_TESTS=OFF -DUSE_PYTHON=OFF -DUSE_QT=OFF -DBoost_USE_STATIC_LIBS=ON ..Which I end up running in thebuilddirectory.This creates for me a Visual Studio solution for which I can build the static OpenImageIO libraries and install them to the
distdirectory, then point my test exexutable project at it by using-DOpenImageIO_DIR=<OIIO_ROOT>\dist\lib\cmake\OpenImageIO. The test executable just prints out the supported extensions for image loading in OIIO.These are the issues I've encountered while generating the VS solution and building both the OpenImageIO libraries and the text executables.
OIIO_BUILD_TESTS=ONwith thex64-windows-statictriplet is broken due to a VC runtime mismatch between the OIIO static library (uses static runtime) and the test executables (uses dynamic runtime). The CMake fix for this would be to put in some generator expressions to change the runtime type, but much easier fixes are to either use thex64-windows-static-mdcommunity triplet forvcpkg, or to turn building tests off instead withOIIO_BUILD_TESTS=OFF.find_package(OpenEXR)into the project beforefind_package(OpenImageIO)otherwise CMake exits with errors. I have a change (DominikGrabiec@a4382d4) which fixes this for me but I'm not sure if it's good as I don't know OpenEXR and how it's used at all.USE_STD_FILESYSTEMon Windows is broken with MSVC because it requires at least C++17 where as OIIO specifies a minimum of C++14. To make this option work we would need to require C++17 ifUSE_STD_FILESYSTEMis switched on, and I don't know how that will play out with other dependencies and projects.USE_QT=OFFis used there is a warning that theQt5library was not found, This is not a fatal error but just looks odd and can be worked around by also specifyingUSE_QT5=OFFto prevent the call tochecked_find_package(Qt5)from emitting the warning. I've got a fix for that in DominikGrabiec@f1603fdALWAYS_PREFER_CONFIGoption inchecked_find_packageis broken for a number of reasons but one of them is that when using theFindOpenEXRmodule it definesOPENEXR_VERSIONbut when using the config version it only hasOpenEXR_VERSIONand therefore it ends up usingIMathversion 2. This fix can be as simple as usingOpenEXR_VERSIONwhen deciding which version of IMath to use but I'm not sure if the old styleOPENEXR_VERSIONis used anywhere else.libheiflibrary has a dependency onlibde265which it does seem to set up correctly for transitive linking but OIIO doesn't use it correctly. I tried to fix it by adding aif(LINKSTATIC)section to theFindLibheif.cmakemodule and do different forms offind_packagethere forlibde265but I couldn't get it to work. The actual fix to make it work came from the vcpkg patches (https://github.com/microsoft/vcpkg/tree/master/ports/openimageio) and I've made a more targetted change in DominikGrabiec@cd6e13dGIF(presumably fromgiflib),webp, andbz2dependencies end up generating full absolute paths in theOpenImageIOTargets.cmakefile that gets generated on install. This may be minor but it does prevent the library from being relocatable ala [BUG] Generated CMake config files contain absolute paths #2559GIFandwebpdependencies end up only finding the debug version of the library so that gets linked into all configurations. I think this was also happening withlibheifbefore the change that I made to make it link. My guess is that this is because the CMakefind_XXXcall ends up searching the vcpkg debug install directory first and just uses that. While thebz2library also includes full paths for its libraries it does have them split up into optimised and debug versions.$<TARGET_NAME_IF_EXISTS:Boost::****>evaluating to empty for some reason. My simple fix is to go back to linkinglibOpenImageIOandlibutilwith${Boost_LIBRARIES}as it used to be but that does generate absolute paths inOpenImageIOTargets.cmake(See DominikGrabiec@ef3483f)Beta Was this translation helpful? Give feedback.
All reactions