Hello,

We ran into an issue when using OpenImageIO 2.1.9.0 (built and installed on windows with vcpkg) and our own version of fmt 5.3.0 (https://github.com/fmtlib/fmt) that we use within our project. Including both <fmt/format.h> and <OpenImageIO/imagecache.h> (possibly the same issue with other headers) will result in the following compilation errors (sorry, the output is in french, but a rough summary is provided below):

OpenImageIO/strutil.h(44,1): warning C4005: 'FMT_USE_GRISU' : redéfinition de macro (compilation du fichier source src\ui\renderoutputview.cpp) ext\fmt-5.3.0\include\fmt\format.h(165): message : voir la définition précédente de 'FMT_USE_GRISU' (compilation du fichier source src\ui\renderoutputview.cpp) OpenImageIO\fmt/ostream.h(22,9): error C2059: erreur de syntaxe : '<' (compilation du fichier source src\ui\renderoutputview.cpp) OpenImageIO\fmt/ostream.h(22,1): error C2238: jetons inattendus avant ';' (compilation du fichier source src\ui\renderoutputview.cpp) OpenImageIO\fmt/ostream.h(25,19): error C2143: erreur de syntaxe : absence de ')' avant '<' (compilation du fichier source src\ui\renderoutputview.cpp) OpenImageIO\fmt/ostream.h(25,19): error C2143: erreur de syntaxe : absence de ';' avant '<' (compilation du fichier source src\ui\renderoutputview.cpp) OpenImageIO\fmt/ostream.h(25,1): error C2059: erreur de syntaxe : '<' (compilation du fichier source src\ui\renderoutputview.cpp) OpenImageIO\fmt/ostream.h(25,1): error C2059: erreur de syntaxe : ')' (compilation du fichier source src\ui\renderoutputview.cpp) OpenImageIO\fmt/ostream.h(25,1): error C2334: jetons inattendus avant ':' ; corps apparent de la fonction ignoré (compilation du fichier source src\ui\renderoutputview.cpp)

... which basically warns about a macro redefinition (FMT_USE_GRISU) and a bunch of syntax errors in OpenImageIO\fmt/ostream.h. The problem is that in this compilation unit, our own copy of fmt/format.h is included first (at version 5.3.0) and conflicts with the version bundled by OpenImageIO (in this case, OpenImageIO/fmt/ostream.h includes OpenImageIO/fmt/format.h, but the header guard FMT_FORMAT_H_ has already been set by our own copy which is at an incompatible version).

A simple workaround would be to match the two versions of fmt, or maybe to set OIIO_USE_FMT=0. However, my question was if fmt was supposed to be exposed in the public API of OpenImageIO in the first place, or if it is just an implementation detail that should not be visible. In the former case, we would need to ensure that either a single version of fmt is used by both OpenImageIO and our project, or that both versions are the same (which unfortunately is not that easy when pulling the package from an external source like vcpkg).

In any case, I'm not sure this is an issue of OpenImageIO per se, but rather a general issue of dependency management in C++. Might there be a way to somehow avoid such conflicts in the future? Possibly by not exposing the fmt headers in the public headers of OIIO, or, if not possible (because of e.g. templates) rename the "fmt::" namespace of the copy of fmt used by OIIO to something like "oiio_fmt::"? (this would not fix the header guard issue though).

Regards,

Alexandre Bléron

artineering.io


_______________________________________________
Oiio-dev mailing list
Oiio-dev@lists.openimageio.org
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org

Reply via email to