Saturday, February 19, 2022

[SOLVED] Using OpenEXR with Bazel?

Issue

I want to use OpenEXR in a Bazel project.

My WORKSPACE.bazel look like this:

# OpenEXR
http_archive(
    name = "openexr",
    build_file = "//third_party:openexr.BUILD",
    sha256 = "53126a6a0d29f37336382f4d41afa8cc78b1958628e5e586469503c41af73f1d",
    strip_prefix = "openexr-2.2.0",
    urls = ["https://github.com/openexr/openexr/archive/v2.2.0.zip"],
)

I am using the openexr.BUILD file provided by seurat

In my BUILD.bazel file I create a test target:

cc_test(
    name = "TestOpenEXR",
    timeout = "short",
    srcs = [
        "test_openexr.cpp",
    ],
    deps = [
        "@googletest//:gtest_main",
        "@openexr//:half",
        "@openexr//:iex",
        "@openexr//:ilm_imf",
        "@openexr//:imath",
    ],
)

When I try to build this target using Bazel (3.5.0) (bazel build) with Ubuntu 18.04 and gcc 7.5.0 I get the following error:

BUILD.bazel:241:11: C++ compilation of rule '@openexr//:imath' failed (Exit 1) gcc failed: error executing command /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++0x' -MD -MF ... (remaining 49 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
In file included from external/openexr/IlmBase/Imath/ImathBox.h:65:0,
                 from external/openexr/IlmBase/Imath/ImathBox.cpp:35:
external/openexr/IlmBase/Imath/ImathVec.h:228:34: error: ISO C++1z does not allow dynamic exception specifications
     const Vec2 & normalizeExc () throw (IEX_NAMESPACE::MathExc);
                                  ^~~~~
external/openexr/IlmBase/Imath/ImathVec.h:232:37: error: ISO C++1z does not allow dynamic exception specifications
     Vec2<T>  normalizedExc () const throw (IEX_NAMESPACE::MathExc);
                                     ^~~~~
external/openexr/IlmBase/Imath/ImathVec.h:440:34: error: ISO C++1z does not allow dynamic exception specifications
     const Vec3 & normalizeExc () throw (IEX_NAMESPACE::MathExc);
                                  ^~~~~
external/openexr/IlmBase/Imath/ImathVec.h:444:37: error: ISO C++1z does not allow dynamic exception specifications
     Vec3<T>  normalizedExc () const throw (IEX_NAMESPACE::MathExc);
                                     ^~~~~
external/openexr/IlmBase/Imath/ImathVec.h:622:37: error: ISO C++1z does not allow dynamic exception specifications
     const Vec4 &    normalizeExc () throw (IEX_NAMESPACE::MathExc);
                                     ^~~~~
external/openexr/IlmBase/Imath/ImathVec.h:626:44: error: ISO C++1z does not allow dynamic exception specifications
     Vec4<T>         normalizedExc () const throw (IEX_NAMESPACE::MathExc);
                                            ^~~~~
external/openexr/IlmBase/Imath/ImathVec.h:714:30: error: ISO C++1z does not allow dynamic exception specifications
 Vec2<short>::normalizeExc () throw (IEX_NAMESPACE::MathExc);
                              ^~~~~
external/openexr/IlmBase/Imath/ImathVec.h:723:37: error: ISO C++1z does not allow dynamic exception specifications
 Vec2<short>::normalizedExc () const throw (IEX_NAMESPACE::MathExc);
                                     ^~~~~
external/openexr/IlmBase/Imath/ImathVec.h:738:28: error: ISO C++1z does not allow dynamic exception specifications
 Vec2<int>::normalizeExc () throw (IEX_NAMESPACE::MathExc);
                            ^~~~~
external/openexr/IlmBase/Imath/ImathVec.h:747:35: error: ISO C++1z does not allow dynamic exception specifications
 Vec2<int>::normalizedExc () const throw (IEX_NAMESPACE::MathExc);
                                   ^~~~~
external/openexr/IlmBase/Imath/ImathVec.h:762:30: error: ISO C++1z does not allow dynamic exception specifications
 Vec3<short>::normalizeExc () throw (IEX_NAMESPACE::MathExc);
                              ^~~~~
external/openexr/IlmBase/Imath/ImathVec.h:771:37: error: ISO C++1z does not allow dynamic exception specifications
 Vec3<short>::normalizedExc () const throw (IEX_NAMESPACE::MathExc);
                                     ^~~~~
external/openexr/IlmBase/Imath/ImathVec.h:786:28: error: ISO C++1z does not allow dynamic exception specifications
 Vec3<int>::normalizeExc () throw (IEX_NAMESPACE::MathExc);
                            ^~~~~
external/openexr/IlmBase/Imath/ImathVec.h:795:35: error: ISO C++1z does not allow dynamic exception specifications
 Vec3<int>::normalizedExc () const throw (IEX_NAMESPACE::MathExc);
                                   ^~~~~
external/openexr/IlmBase/Imath/ImathVec.h:809:30: error: ISO C++1z does not allow dynamic exception specifications
 Vec4<short>::normalizeExc () throw (IEX_NAMESPACE::MathExc);
                              ^~~~~
external/openexr/IlmBase/Imath/ImathVec.h:818:37: error: ISO C++1z does not allow dynamic exception specifications
 Vec4<short>::normalizedExc () const throw (IEX_NAMESPACE::MathExc);
                                     ^~~~~
external/openexr/IlmBase/Imath/ImathVec.h:833:28: error: ISO C++1z does not allow dynamic exception specifications
 Vec4<int>::normalizeExc () throw (IEX_NAMESPACE::MathExc);
                            ^~~~~
external/openexr/IlmBase/Imath/ImathVec.h:842:35: error: ISO C++1z does not allow dynamic exception specifications
 Vec4<int>::normalizedExc () const throw (IEX_NAMESPACE::MathExc);
                                   ^~~~~
external/openexr/IlmBase/Imath/ImathVec.h:1212:26: error: ISO C++1z does not allow dynamic exception specifications
 Vec2<T>::normalizeExc () throw (IEX_NAMESPACE::MathExc)
                          ^~~~~
external/openexr/IlmBase/Imath/ImathVec.h:1249:33: error: ISO C++1z does not allow dynamic exception specifications
 Vec2<T>::normalizedExc () const throw (IEX_NAMESPACE::MathExc)
                                 ^~~~~
external/openexr/IlmBase/Imath/ImathVec.h:1704:26: error: ISO C++1z does not allow dynamic exception specifications
 Vec3<T>::normalizeExc () throw (IEX_NAMESPACE::MathExc)
                          ^~~~~
external/openexr/IlmBase/Imath/ImathVec.h:1743:33: error: ISO C++1z does not allow dynamic exception specifications
 Vec3<T>::normalizedExc () const throw (IEX_NAMESPACE::MathExc)
                                 ^~~~~
external/openexr/IlmBase/Imath/ImathVec.h:2109:26: error: ISO C++1z does not allow dynamic exception specifications
 Vec4<T>::normalizeExc () throw (IEX_NAMESPACE::MathExc)
                          ^~~~~
external/openexr/IlmBase/Imath/ImathVec.h:2150:33: error: ISO C++1z does not allow dynamic exception specifications
 Vec4<T>::normalizedExc () const throw (IEX_NAMESPACE::MathExc)
                                 ^~~~~
cc1plus: warning: unrecognized command line option '-Wno-deprecated-register'
cc1plus: warning: unrecognized command line option '-Wno-string-conversion'

I am using a .bazelrc file that should force GCC to use C++17 (as good as it can ;)):

build:gcc --cxxopt=-std=c++17

Any ideas how I can get around the ISO C++1z error?


Solution

In the meantime, I was able to solve the problem. Base on the BUILD file file from seurat I took an up to date master version von OpenEXR and started to fix all issues. The final BUILD.bazel was tested successfully with Ubuntu 16.08 GCC, LLVM and Windows 10 VS2019.

I created my own bazel branch for the OpenEXR: https://github.com/Vertexwahn/openexr/tree/bazel

Update OpenEXR has now official Bazel support.



Answered By - Vertexwahn
Answer Checked By - Marilyn (WPSolving Volunteer)