Andrei Popescu
Andrei Popescu

Reputation: 7

Compiling a C++ app with ONNX runtime headers, using -std=c++20 have a lot of errors

Using ONNX runtime with g++ (latest, v12), I have a lot of errors if I use "-std=c++20". Like:

W:/projects/AI/ONNX/onnxruntime-win-x64-1.20.1/include/onnxruntime_cxx_inline.h: In lambda function:
W:/projects/AI/ONNX/onnxruntime-win-x64-1.20.1/include/onnxruntime_cxx_inline.h:1968:27: error: 'const OrtApi' {aka 'const struct OrtApi'} has no member named 'ReleaseAvailableProviders'
 1968 |     ThrowOnError(GetApi().ReleaseAvailableProviders(providers, len));
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~
W:/projects/AI/ONNX/onnxruntime-win-x64-1.20.1/include/onnxruntime_cxx_inline.h: In function 'std::vector<std::__cxx11::basic_string<char> > Ort::GetAvailableProviders()':
W:/projects/AI/ONNX/onnxruntime-win-x64-1.20.1/include/onnxruntime_cxx_inline.h:1971:25: error: 'const OrtApi' {aka 'const struct OrtApi'} has no member named 'GetAvailableProviders'
 1971 |   ThrowOnError(GetApi().GetAvailableProviders(&providers, &len));
      |                         ^~~~~~~~~~~~~~~~~~~~~
W:/projects/AI/ONNX/onnxruntime-win-x64-1.20.1/include/onnxruntime_cxx_inline.h: In constructor 'Ort::ShapeInferContext::ShapeInferContext(const OrtApi*, OrtShapeInferContext*)':
W:/projects/AI/ONNX/onnxruntime-win-x64-1.20.1/include/onnxruntime_cxx_inline.h:2002:31: error: 'const OrtApi' {aka 'const struct OrtApi'} has no member named 'ShapeInferContext_GetInputCount'
 2002 |   Ort::ThrowOnError(ort_api_->ShapeInferContext_GetInputCount(ctx_, &input_count));

If I omit "-std=c++20" (or any std flag), I can compile just fine and code works as expected. It's not a big deal, but I'm curious why is that?

Appears that these inline functions use some members that are not defined.

It can be easily reproduced by empty main() like this. Just cxx header used from runtime. Compile with g++. Using ONNX runtime 1.20.1 from here
https://github.com/microsoft/onnxruntime/releases/download/v1.20.1/onnxruntime-win-x64-1.20.1.zip

Again, if I don't specify and STD to compiler, it compiles just fine.

#include <iostream>
//#include <onnxruntime_c_api.h>
#include <onnxruntime_cxx_api.h>
#include <vector>


int
main()
{

return 0;
}

Upvotes: -1

Views: 57

Answers (1)

Andrei Popescu
Andrei Popescu

Reputation: 7

Ok, sorry to answer my own question, but yeah.. maybe others can benefit.
Seems that MSFT and their ONNY runtime don't follow strict c++ rules.

So compile with "-std=c++17" will fail. Instead, when using GCC, compile with "-std=gnu++17" or "-std=gnu++20" will be ok.

Btw, I found that if you don't specify "-std=.." at all, GNU compiler will use a default "g++17" or whatever was built for. So that's why is working silently on my side.

c++ vs. gnu++ Differences

Upvotes: 0

Related Questions