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

multiple definition of `ocvrs_create_string`

Open wilwade opened this issue 1 year ago • 9 comments

Running into an issue with opencv that I haven't seen anywhere else.

  • OS: clean Github Action Runner on Ubuntu Latest (Note this compiles fine on my M1 Mac)
  • Rust: Stable v1.80.0
 = note: /usr/bin/ld: /home/runner/work/metadata-portal/metadata-portal/target/debug/deps/libopencv-1885957c5723ab99.rlib(opencv-1885957c5723ab99.opencv.b72e93c0dd09b42b-cgu.1.rcgu.o): in function `ocvrs_create_string':
          /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/opencv-0.92.1/src/templ.rs:114: multiple definition of `ocvrs_create_string'; /home/runner/work/metadata-portal/metadata-portal/target/debug/deps/libopencv-1036cca749d0c639.rlib(opencv-1036cca749d0c639.opencv.3be91388ef299701-cgu.0.rcgu.o):/home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/opencv-0.88.9/src/templ.rs:114: first defined here
          /usr/bin/ld: /home/runner/work/metadata-portal/metadata-portal/target/debug/deps/libopencv-1885957c5723ab99.rlib(opencv-1885957c5723ab99.opencv.b72e93c0dd09b42b-cgu.1.rcgu.o): in function `ocvrs_create_byte_string':
          /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/opencv-0.92.1/src/templ.rs:121: multiple definition of `ocvrs_create_byte_string'; /home/runner/work/metadata-portal/metadata-portal/target/debug/deps/libopencv-1036cca749d0c639.rlib(opencv-1036cca749d0c639.opencv.3be91388ef299701-cgu.0.rcgu.o):/home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/opencv-0.88.9/src/templ.rs:121: first defined here
          collect2: error: ld returned 1 exit status
  • OSS PR that is throwing the error: https://github.com/frequency-chain/metadata-portal/pull/86
  • GitHub Action with the error: https://github.com/frequency-chain/metadata-portal/actions/runs/10180366033/job/28158081534?pr=86
  • Text logs: ci-logs.txt

Perhaps I am just missing something basic, but the workflow is doing apt install -y clang libclang-dev libopencv-dev

wilwade avatar Jul 31 '24 13:07 wilwade

There is 2 different version of opencv in your dependency tree:

2024-07-31T12:40:06.4812650Z   Downloaded opencv v0.92.1
2024-07-31T12:40:06.5743422Z   Downloaded opencv v0.88.9

and apparently that doesn't work, which is logical when I think about it. So the solution would be to make sure there is only a single opencv version. As far as I can see the version 0.92 is the direct dep, but 0.88 seems to be a transitive dependency.

twistedfall avatar Jul 31 '24 14:07 twistedfall

Ah that does make sense. I missed that looking through everything.

Thanks. I switched to use only 0.88.9 and that fixed it. Not sure why I didn't get the same error on Mac, but working and knowing why is 💯.

wilwade avatar Jul 31 '24 15:07 wilwade

On the other hand it's actually a bug and it looks like it's easy to fix, can you please try to use v0.92.2 to see if the error is fixed in your case?

twistedfall avatar Aug 01 '24 12:08 twistedfall

You should also not need this lints section in your Cargo.toml anymore:

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = [
  'cfg(ocvrs_opencv_branch_32)',
] }

twistedfall avatar Aug 01 '24 12:08 twistedfall

Testing out now... https://github.com/frequency-chain/metadata-portal/pull/87

wilwade avatar Aug 01 '24 17:08 wilwade

You should also not need this lints section in your Cargo.toml anymore:

That still error'd on me:

error: unexpected `cfg` condition name: `ocvrs_opencv_branch_32`
  --> cli/src/common/camera.rs:55:15
   |
55 |     #[cfg(not(ocvrs_opencv_branch_32))]
   |               ^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: expected names are: `clippy`, `debug_assertions`, `doc`, `docsrs`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `sanitizer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `ub_checks`, `unix`, and `windows`
   = help: consider using a Cargo feature instead
   = help: or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:
            [lints.rust]
            unexpected_cfgs = { level = "warn", check-cfg = ['cfg(ocvrs_opencv_branch_32)'] }
   = help: or consider adding `println!("cargo::rustc-check-cfg=cfg(ocvrs_opencv_branch_32)");` to the top of the `build.rs`
   = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
   = note: `-D unexpected-cfgs` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(unexpected_cfgs)]`

https://github.com/frequency-chain/metadata-portal/actions/runs/10202774937/job/28227646901

Testing again with keeping the [lints.rust]: https://github.com/frequency-chain/metadata-portal/actions/runs/10202867537/job/28227926403?pr=87

wilwade avatar Aug 01 '24 17:08 wilwade

I see, I’ll need to check why the lints are still needed

twistedfall avatar Aug 01 '24 17:08 twistedfall

Nope. Same error: https://github.com/frequency-chain/metadata-portal/actions/runs/10202867537/job/28227926403?pr=87

error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/runner/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/runner/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/runner/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/snap/bin:/home/runner/.local/bin:/opt/pipx_bin:/home/runner/.cargo/bin:/home/runner/.config/composer/vendor/bin:/usr/local/.ghcup/bin:/home/runner/.dotnet/tools:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin" VSLANG="1033" "cc" "-m64" "/tmp/rustcNOJAnL/symbols.o" "/home/runner/work/metadata-portal/metadata-portal/target/debug/deps/metadata_cli-7b11c7f58e480db9.metadata_cli.49bc5debc42862cd-cgu.00.rcgu.o" "/home/runner/work/metadata-portal/metadata-portal/target/debug/deps/metadata_cli-7b11c7f58e480db9.metadata_cli.49bc5debc42862cd-cgu.01.rcgu.o" "/home/runner/work/metadata-portal/metadata-portal/target/debug/deps/metadata
  = note: /usr/bin/ld: /home/runner/work/metadata-portal/metadata-portal/target/debug/deps/libopencv-51c564336398a82f.rlib(opencv-51c564336398a82f.opencv.c24af44cca3222fd-cgu.1.rcgu.o): in function `ocvrs_create_string':
          /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/opencv-0.92.2/src/templ.rs:114: multiple definition of `ocvrs_create_string'; /home/runner/work/metadata-portal/metadata-portal/target/debug/deps/libopencv-1036cca749d0c639.rlib(opencv-1036cca749d0c639.opencv.3be91388ef299701-cgu.0.rcgu.o):/home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/opencv-0.88.9/src/templ.rs:114: first defined here
          /usr/bin/ld: /home/runner/work/metadata-portal/metadata-portal/target/debug/deps/libopencv-51c564336398a82f.rlib(opencv-51c564336398a82f.opencv.c24af44cca3222fd-cgu.1.rcgu.o): in function `ocvrs_create_byte_string':
          /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/opencv-0.92.2/src/templ.rs:121: multiple definition of `ocvrs_create_byte_string'; /home/runner/work/metadata-portal/metadata-portal/target/debug/deps/libopencv-1036cca749d0c639.rlib(opencv-1036cca749d0c639.opencv.3be91388ef299701-cgu.0.rcgu.o):/home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/opencv-0.88.9/src/templ.rs:121: first defined here
          collect2: error: ld returned 1 exit status

wilwade avatar Aug 01 '24 17:08 wilwade

Thanks for checking! I’ll try to see why it didn’t work for you

twistedfall avatar Aug 01 '24 17:08 twistedfall

This should now be fixed as long as one of the used versions is 0.93.1, can you please check to confirm?

twistedfall avatar Sep 22 '24 10:09 twistedfall

I had to keep the lint line in, but it is now working! Thanks for the fix!

https://github.com/frequency-chain/metadata-portal

Retained Lint:

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = [
  'cfg(ocvrs_opencv_branch_32)',
] }

wilwade avatar Sep 23 '24 13:09 wilwade

Yeah, I think that the lint warnings are triggered by the older version of the crate

twistedfall avatar Sep 23 '24 13:09 twistedfall