onnxruntime: [Build] C++ API calling fail: error C2280: 'Ort::Value::Value(const Ort::Value &)' : attempt to reference a deleted function

Describe the issue

error C2280: ‘Ort::Value::Value(const Ort::Value &)’ : attempt to reference a deleted function

Urgency

Very urgent

Target platform

windows

Build script

noio

Error / output

error C2280: ‘Ort::Value::Value(const Ort::Value &)’ : attempt to reference a deleted function

Here is the c++ caling code:

 std::vector<Ort::Value> ort_inputs;
  for (int i = 0; i < inputNames.size(); ++i) {
    auto ort_value = Ort::Value::CreateTensor<float>(
        memoryInfo, static_cast<float *>(inputs[i].data), inputs[i].get_size(),
        inputShapes[i].data(), inputShapes[i].size());
    assert(ort_value.IsTensor());
    ort_inputs.emplace_back(ort_value);
  }

try {
    std::vector<Ort::Value> ort_outputs;
    ort_outputs = session.Run(
        Ort::RunOptions{nullptr}, inputNames.data(), ort_inputs.data(),
        inputNames.size(), outputNames.data(), outputNames.size());
}

can not build

Visual Studio Version

2019

GCC / Compiler Version

No response

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

@raisinglc03

Ah, I see what the problem would be in your case. push_back is trying to make a copy of ‘outputtensor’, if you push_back with a std::move() it should work:

vector<Ort::Value> outputtensors;
auto outputtensor = Ort::Value::CreateTensor<float>( 
                memoryInfo, tmpTensorValue.data(), tmpOutTensorSize, tmpOutDim.data(), tmpOutDim.size()
            );
outputtensors.push_back(std::move(outputtensor));

Thanks! It work!