rust-protobuf icon indicating copy to clipboard operation
rust-protobuf copied to clipboard

Protobuf Version Mismatch Fix Guide

Open naoNao89 opened this issue 1 year ago • 1 comments

The error you're encountering is due to a version mismatch between the protobuf crate and the onnx-protobuf crate. Specifically:

  • Your project is using protobuf version 3.5.1
  • The onnx-protobuf crate (version 0.2.3) was compiled against protobuf version 3.4.0

This mismatch causes the error:

cannot find value `VERSION_3_4_0` in crate `protobuf`
  --> .cargo/registry/src/index.crates.io-6f17d22bba15001f/onnx-protobuf-0.2.3/src/proto/onnx.rs:27:47
   |
27 | const _PROTOBUF_VERSION_CHECK: () = protobuf::VERSION_3_4_0;
   |                                               ^^^^^^^^^^^^^ help: a constant with a similar name exists: `VERSION_3_5_1`
   |
  ::: target/debug/build/protobuf-9067af482d19c48e/out/version.rs:7:1
   |
7  | pub const VERSION_3_5_1: () = ();
   | --------------------------- similarly named constant `VERSION_3_5_1` defined here

Resolution Steps

  1. Locate the onnx.rs file: Path: .cargo/registry/src/index.crates.io-6f17d22bba15001f/onnx-protobuf-0.2.3/src/proto/onnx.rs

  2. Open onnx.rs in a text editor.

  3. Find this line:

    const _PROTOBUF_VERSION_CHECK: () = protobuf::VERSION_3_4_0;
    
  4. Change it to:

    const _PROTOBUF_VERSION_CHECK: () = protobuf::VERSION_3_5_1;
    
  5. Save the file.

  6. Clean and rebuild your project:

    cargo clean
    cargo build
    

Important Notes

  • This is a temporary fix. The change will be overwritten when you update your dependencies.
  • A more permanent solution would involve updating onnx-protobuf to a version compatible with protobuf 3.5.1, or pinning protobuf to version 3.4.0 in your Cargo.toml.

naoNao89 avatar Aug 30 '24 20:08 naoNao89

I think this issue should be reported to the authors of the onnx-protobuf crate. The issue doesn't belong to this project.

plusvic avatar Sep 07 '24 09:09 plusvic