onnxruntime: [Build] Failure to build with shared library flatbuffers 23.3.3

Describe the issue

Trying to build main on Arch Linux fails because Arch Linux packages flatbuffers as a shared library. The flatbuffers target then becomes flatbuffers::flatbuffers_shared, not flatbuffers::flatbuffers as is used in onnxruntime. As a result, CMake fails to find the target.

Replacing flatbuffers::flatbuffers with flatbuffers::flatbuffers_shared makes it pass the CMake stage, but fails to build as well:

onnxruntime/onnxruntime/core/flatbuffers/schema/ort.fbs.h: In member function ‘bool onnxruntime::fbs::DimensionValue::Verify(flatbuffers::Verifier&) const’:
onnxruntime/onnxruntime/core/flatbuffers/schema/ort.fbs.h:553:31: error: no matching function for call to ‘onnxruntime::fbs::DimensionValue::VerifyField<int8_t>(flatbuffers::Verifier&, onnxruntime::fbs::DimensionValue::FlatBuffersVTableOffset) const’
  553 |            VerifyField<int8_t>(verifier, VT_DIM_TYPE) &&
      |            ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/flatbuffers/flatbuffer_builder.h:33,
                 from /usr/include/flatbuffers/flatbuffers.h:29,
                 from onnxruntime/onnxruntime/core/flatbuffers/schema/ort.fbs.h:7:
/usr/include/flatbuffers/table.h:115:8: note: candidate: ‘template<class T> bool flatbuffers::Table::VerifyField(const flatbuffers::Verifier&, flatbuffers::voffset_t, size_t) const’
  115 |   bool VerifyField(const Verifier &verifier, voffset_t field,
      |        ^~~~~~~~~~~
/usr/include/flatbuffers/table.h:115:8: note:   candidate expects 3 arguments, 2 provided

There’s many more errors like this, possibly because of API changes?

Considering flatbuffers is designed as a header-only library, maybe it makes sense to include it as a submodule in this repository, same as protobuf?

Urgency

No response

Target platform

x86_64

Build script

./build.sh --config RelWithDebInfo --build_shared_lib --parallel

Error / output

CMake Error at onnxruntime_flatbuffers.cmake:18 (add_dependencies):
  The dependency target "flatbuffers::flatbuffers" of target
  "onnxruntime_flatbuffers" does not exist.
Call Stack (most recent call first):
  CMakeLists.txt:1584 (include)


CMake Error at onnxruntime_common.cmake:120 (add_dependencies):
  The dependency target "flatbuffers::flatbuffers" of target
  "onnxruntime_common" does not exist.
Call Stack (most recent call first):
  CMakeLists.txt:1584 (include)


CMake Error at onnxruntime_graph.cmake:89 (add_dependencies):
  The dependency target "flatbuffers::flatbuffers" of target
  "onnxruntime_graph" does not exist.
Call Stack (most recent call first):
  CMakeLists.txt:1584 (include)


CMake Error at onnxruntime_framework.cmake:100 (add_dependencies):
  The dependency target "flatbuffers::flatbuffers" of target
  "onnxruntime_framework" does not exist.
Call Stack (most recent call first):
  CMakeLists.txt:1584 (include)


CMake Error at onnxruntime_util.cmake:19 (add_dependencies):
  The dependency target "flatbuffers::flatbuffers" of target
  "onnxruntime_util" does not exist.
Call Stack (most recent call first):
  CMakeLists.txt:1584 (include)


CMake Error at onnxruntime_providers.cmake:284 (add_dependencies):
  The dependency target "flatbuffers::flatbuffers" of target
  "onnxruntime_providers" does not exist.
Call Stack (most recent call first):
  CMakeLists.txt:1584 (include)


CMake Error at onnxruntime_optimizer.cmake:106 (add_dependencies):
  The dependency target "flatbuffers::flatbuffers" of target
  "onnxruntime_optimizer" does not exist.
Call Stack (most recent call first):
  CMakeLists.txt:1584 (include)


CMake Error at onnxruntime_session.cmake:46 (add_dependencies):
  The dependency target "flatbuffers::flatbuffers" of target
  "onnxruntime_session" does not exist.
Call Stack (most recent call first):
  CMakeLists.txt:1584 (include)


CMake Error at onnxruntime.cmake:100 (add_dependencies):
  The dependency target "flatbuffers::flatbuffers" of target "onnxruntime"
  does not exist.
Call Stack (most recent call first):
  CMakeLists.txt:1584 (include)


CMake Error at onnxruntime_unittests.cmake:695 (add_dependencies):
  The dependency target "flatbuffers::flatbuffers" of target
  "onnxruntime_test_utils" does not exist.
Call Stack (most recent call first):
  CMakeLists.txt:1584 (include)


CMake Error at onnxruntime_unittests.cmake:723 (add_dependencies):
  The dependency target "flatbuffers::flatbuffers" of target
  "onnx_test_runner_common" does not exist.
Call Stack (most recent call first):
  CMakeLists.txt:1584 (include)


CMake Error at onnxruntime_unittests.cmake:47 (add_dependencies):
  The dependency target "flatbuffers::flatbuffers" of target
  "onnxruntime_test_all" does not exist.
Call Stack (most recent call first):
  onnxruntime_unittests.cmake:798 (AddTest)
  CMakeLists.txt:1584 (include)


CMake Error at onnxruntime_unittests.cmake:859 (add_dependencies):
  The dependency target "flatbuffers::flatbuffers" of target
  "onnx_test_data_proto" does not exist.
Call Stack (most recent call first):
  CMakeLists.txt:1584 (include)


CMake Error at onnxruntime_unittests.cmake:47 (add_dependencies):
  The dependency target "flatbuffers::flatbuffers" of target
  "onnxruntime_shared_lib_test" does not exist.
Call Stack (most recent call first):
  onnxruntime_unittests.cmake:1251 (AddTest)
  CMakeLists.txt:1584 (include)


CMake Error at onnxruntime_unittests.cmake:47 (add_dependencies):
  The dependency target "flatbuffers::flatbuffers" of target
  "onnxruntime_global_thread_pools_test" does not exist.
Call Stack (most recent call first):
  onnxruntime_unittests.cmake:1276 (AddTest)
  CMakeLists.txt:1584 (include)


CMake Error at onnxruntime_unittests.cmake:47 (add_dependencies):
  The dependency target "flatbuffers::flatbuffers" of target
  "onnxruntime_api_tests_without_env" does not exist.
Call Stack (most recent call first):
  onnxruntime_unittests.cmake:1286 (AddTest)
  CMakeLists.txt:1584 (include)


CMake Error at onnxruntime_unittests.cmake:47 (add_dependencies):
  The dependency target "flatbuffers::flatbuffers" of target
  "onnxruntime_customopregistration_test" does not exist.
Call Stack (most recent call first):
  onnxruntime_unittests.cmake:1510 (AddTest)
  CMakeLists.txt:1584 (include)


CMake Error at onnxruntime.cmake:211 (target_link_libraries):
  Target "onnxruntime" links to:

    flatbuffers::flatbuffers

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

Call Stack (most recent call first):
  CMakeLists.txt:1584 (include)


CMake Error at onnxruntime_unittests.cmake:55 (target_link_libraries):
  Target "onnxruntime_test_all" links to:

    flatbuffers::flatbuffers

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

Call Stack (most recent call first):
  onnxruntime_unittests.cmake:798 (AddTest)
  CMakeLists.txt:1584 (include)


CMake Error at onnxruntime_unittests.cmake:1002 (target_link_libraries):
  Target "onnx_test_runner" links to:

    flatbuffers::flatbuffers

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

Call Stack (most recent call first):
  CMakeLists.txt:1584 (include)


CMake Error at onnxruntime_unittests.cmake:1203 (target_link_libraries):
  Target "onnxruntime_perf_test" links to:

    flatbuffers::flatbuffers

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

Call Stack (most recent call first):
  CMakeLists.txt:1584 (include)


-- Generating done

Visual Studio Version

No response

GCC / Compiler Version

No response

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Comments: 21 (7 by maintainers)

Commits related to this issue

Most upvoted comments

1.15.0 is out, and now start build failure with flatbuffers 23.5.26

a little snip. the full log generate 3.7Mg of log with -j1

[  3%] Building CXX object CMakeFiles/onnxruntime_flatbuffers.dir/tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/flatbuffers_utils.cc.o
/opt/cuda/bin/g++ -DCPUINFO_SUPPORTED_PLATFORM=1 -DDNNL_OPENMP -DEIGEN_MPL2_ONLY -DEIGEN_USE_THREADS -DENABLE_ATEN -DENABLE_CPU_FP16_TRAINING_OPS -DENABLE_STRIDED_TENSORS -DENABLE_TRAINING -DENABLE_TRAINING_APIS -DENABLE_TRAINING_CORE -DENABLE_TRAINING_OPS -DNSYNC_ATOMIC_CPP11 -DONNX_ML=1 -DONNX_NAMESPACE=onnx -DONNX_USE_LITE_PROTO=1 -DORT_ENABLE_STREAM -DORT_USE_NCCL=1 -DPLATFORM_POSIX -DPROTOBUF_USE_DLLS -DUSE_CUDA=1 -DUSE_DNNL=1 -DUSE_FLASH_ATTENTION=1 -DUSE_MPI=1 -DUSE_NCCL_P2P=1 -D_GNU_SOURCE -D__ONNX_NO_DOC_STRINGS -I/tmp/makepkg/python-onnxruntime/src/onnxruntime/include/onnxruntime -I/tmp/makepkg/python-onnxruntime/src/onnxruntime/include/onnxruntime/core/session -I/tmp/makepkg/python-onnxruntime/src/onnxruntime/orttraining/orttraining/training_api/include -I/tmp/makepkg/python-onnxruntime/src/build/_deps/pytorch_cpuinfo-src/include -I/tmp/makepkg/python-onnxruntime/src/build -I/tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime -I/tmp/makepkg/python-onnxruntime/src/onnxruntime/orttraining -I/tmp/makepkg/python-onnxruntime/src/build/_deps/onnx-src -I/tmp/makepkg/python-onnxruntime/src/build/_deps/onnx-build -I/tmp/makepkg/python-onnxruntime/src/build/_deps/gsl-src/include -march=native -O2 -pipe -fno-plt -fexceptions         -Wp,-D_FORTIFY_SOURCE=0 -Wformat -Werror=format-security         -fstack-clash-protection -fcf-protection -Wp,-D_GLIBCXX_ASSERTIONS -g -ffile-prefix-map=/tmp/makepkg/python-onnxruntime/src=/usr/src/debug/python-onnxruntime -Wno-maybe-uninitialized -ffunction-sections -fdata-sections -DCPUINFO_SUPPORTED -g -std=gnu++17 -fPIC -Wall -Wextra -Wno-deprecated-copy -Wno-nonnull-compare -Werror -MD -MT CMakeFiles/onnxruntime_flatbuffers.dir/tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/flatbuffers_utils.cc.o -MF CMakeFiles/onnxruntime_flatbuffers.dir/tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/flatbuffers_utils.cc.o.d -o CMakeFiles/onnxruntime_flatbuffers.dir/tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/flatbuffers_utils.cc.o -c /tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/flatbuffers_utils.cc
In file included from /usr/include/flatbuffers/array.h:25,
                 from /usr/include/flatbuffers/flatbuffers.h:24,
                 from /tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/schema/ort.fbs.h:7,
                 from /tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/flatbuffers_utils.cc:8:
/usr/include/flatbuffers/vector.h:148:56: error: redeclared with 2 template parameters
  148 | template<typename T, typename SizeT = uoffset_t> class Vector {
      |                                                        ^~~~~~
In file included from /tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/flatbuffers_utils.cc:4:
/tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/flatbuffers_utils.h:25:7: note: previous declaration 'template<class T> class flatbuffers::Vector' used 1 template parameter
   25 | class Vector;
      |       ^~~~~~
/usr/include/flatbuffers/vector.h:304:60: error: wrong number of template arguments (2, should be 1)
  304 | template<typename T> using Vector64 = Vector<T, uoffset64_t>;
      |                                                            ^
/tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/flatbuffers_utils.h:25:7: note: provided for 'template<class T> class flatbuffers::Vector'
   25 | class Vector;
      |       ^~~~~~
In file included from /usr/include/flatbuffers/buffer_ref.h:21,
                 from /usr/include/flatbuffers/flatbuffers.h:27:
/usr/include/flatbuffers/verifier.h:121:41: error: wrong number of template arguments (2, should be 1)
  121 |   bool VerifyVector(const Vector<T, LenT> *const vec) const {
      |                                         ^
/tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/flatbuffers_utils.h:25:7: note: provided for 'template<class T> class flatbuffers::Vector'
   25 | class Vector;
      |       ^~~~~~
/usr/include/flatbuffers/verifier.h:128:49: error: wrong number of template arguments (2, should be 1)
  128 |   bool VerifyVector(const Vector<const T *, LenT> *const vec) const {
      |                                                 ^
/tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/flatbuffers_utils.h:25:7: note: provided for 'template<class T> class flatbuffers::Vector'
   25 | class Vector;
      |       ^~~~~~
/usr/include/flatbuffers/verifier.h:128:8: error: 'template<int& ...<anonymous>, class T, class LenT> bool flatbuffers::Verifier::VerifyVector(const int*) const' cannot be overloaded with 'template<int& ...<anonymous>, class T, class LenT> bool flatbuffers::Verifier::VerifyVector(const int*) const'
  128 |   bool VerifyVector(const Vector<const T *, LenT> *const vec) const {
      |        ^~~~~~~~~~~~
/usr/include/flatbuffers/verifier.h:121:8: note: previous declaration 'template<int& ...<anonymous>, class T, class LenT> bool flatbuffers::Verifier::VerifyVector(const int*) const'
  121 |   bool VerifyVector(const Vector<T, LenT> *const vec) const {
      |        ^~~~~~~~~~~~
/usr/include/flatbuffers/verifier.h:224:58: error: wrong number of template arguments (2, should be 1)
  224 |   bool VerifyNestedFlatBuffer(const Vector<uint8_t, SizeT> *const buf,
      |                                                          ^
/tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/flatbuffers_utils.h:25:7: note: provided for 'template<class T> class flatbuffers::Vector'
   25 | class Vector;
      |       ^~~~~~
/usr/include/flatbuffers/verifier.h: In member function 'bool flatbuffers::Verifier::VerifyVector(const int*) const':
/usr/include/flatbuffers/verifier.h:129:62: error: wrong number of template arguments (2, should be 1)
  129 |     return VerifyVector(reinterpret_cast<const Vector<T, LenT> *>(vec));
      |                                                              ^
/tmp/makepkg/python-onnxruntime/src/onnxruntime/onnxruntime/core/flatbuffers/flatbuffers_utils.h:25:7: note: provided for 'template<class T> class flatbuffers::Vector'
   25 | class Vector;
      |       ^~~~~~

I was able to build v1.14.1 with the following change

-  dim_block_size.back() = 1;
+  dim_block_size[num_dims-1] = 1;