Skip to content

Compatibility of onnx with g++ #23304

@MoniqueSciortino

Description

@MoniqueSciortino

Describe the issue

I installed the Runtime precompiled binaries from
https://github.com/microsoft/onnxruntime/releases.
Now I am trying to use them inside a C++ file on Visual Studio Code. The code is

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

int main() {
    // Initialize ONNX Runtime environment
    std::cout << "Initializing ONNX Runtime..." << std::endl;
    /*
    try {
        // Create an ONNX Runtime session options object
        onnxruntime::SessionOptions session_options;

        // Create ONNX session
        onnxruntime::InferenceSession onnx_session(session_options);

        // Specify the path to the ONNX model
        const std::string model_path = "RFModel.onnx";  // Replace with your model path
        onnx_session.Load(model_path);

        std::cout << "Model loaded successfully!" << std::endl;

        // Prepare input and output tensors (you need to provide input data here)

        std::vector<onnxruntime::InputTensor> input_tensors;   // Set up input tensors (prepare data)
        std::vector<onnxruntime::OutputTensor> output_tensors; // Prepare output tensors

        // Run inference
        onnx_session.Run(input_tensors, output_tensors);

        std::cout << "Inference completed!" << std::endl;

    } catch (const std::exception &e) {
        std::cerr << "Error: " << e.what() << std::endl;
    }
    */
    return 0;
}

To run I am using the command:
g++ -O3 trial_onnx.cpp -I"C:/Users/moniq/Downloads/onnxruntime/include" -L"C:/Users/moniq/Downloads/onnxruntime/lib" -lonnxruntime -o out

However I am getting errors like:

C:/Users/moniq/Downloads/onnxruntime/include/onnxruntime_c_api.h:310:30: error: typedef 'Return_type_success' is initialized (use decltype instead)
typedef Return_type_success(return == 0) OrtStatus* OrtStatusPtr;

Is this because Onnx is not compatible with g++?

To reproduce

I would not like to change the compiler. Is there a remedy for this?

Urgency

No response

Platform

Windows

OS Version

24h2

ONNX Runtime Installation

Built from Source

ONNX Runtime Version or Commit ID

latest

ONNX Runtime API

C++

Architecture

X64

Execution Provider

Default CPU

Execution Provider Library Version

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions