thewh1teagle / pyannote-rs

pyannote audio diarization in rust
http://crates.io/crates/pyannote-rs
MIT License
32 stars 3 forks source link

LINK : fatal error LNK1181: cannot open input file 'onnxruntime.lib' #1

Closed altunenes closed 3 months ago

altunenes commented 3 months ago

This project is really cool and working very well!! :)

(I hate to be that person who always comes with such problems) but it fails simply with:

error: linking with link.exe failed: exit code: 1181 LINK : fatal error LNK1181: cannot open input file 'onnxruntime.lib'

git clone cd pyannote-rs get models/example waw cargo run

but if I change tihs: ort = { version = "2.0.0-rc.4" }

with this, it works without error ort = { version = "2.0.0-rc.4", features = ["cuda", "load-dynamic"] } or with this (both is work): ort = { version = "2.0.0-rc.4", features = [ "load-dynamic"] }

Also, it works pretty fast actually! segmentation is better! But identification looked pretty much the same to me on my tests (well I can say 'slightly better, not significantly).

Thank you for your contributions!

thewh1teagle commented 3 months ago

This project is really cool and working very well!! :)

Thanks

By the way I really appreciate bug reports. More than feature requests ;)

error: linking with link.exe failed: exit code: 1181 LINK : fatal error LNK1181: cannot open input file 'onnxruntime.lib'

Weird. I tested it on macOS and Windows. Fresh build works.

commands *Note: make sure to install [prerequisites](https://github.com/thewh1teagle/pyannote-rs/blob/main/BUILDING.md#prerequisites)* *Note: better to run from cmd.exe and install wget with winget* ```console git clone https://github.com/thewh1teagle/pyannote-rs --recursive wget https://github.com/pengzhendong/pyannote-onnx/raw/master/pyannote_onnx/segmentation-3.0.onnx wget https://github.com/k2-fsa/sherpa-onnx/releases/download/speaker-recongition-models/wespeaker_en_voxceleb_CAM++.onnx wget https://github.com/thewh1teagle/sherpa-rs/releases/download/v0.1.0/6_speakers.wav cargo run --example diarize 6_speakers.wav ```

ort = { version = "2.0.0-rc.4", features = ["cuda", "load-dynamic"] }

Then looks like for some reason it failed to link onxxruntime statically but works dynamically (Although on my end it works)

Also, it works pretty fast actually! segmentation is better! But identification looked pretty much the same to me on my tests (well I can say 'slightly better, not significantly).

Yes it's super fast! Like one hour in a minute or less on CPU. And the speaker identification is pretty accurate. Wdym by segmentation is better?

Few things you can try check

  1. Check that this URL accessible onnx lib
  2. Check where onnxruntime.lib and if it exists
Get-ChildItem -Recurse -Filter "*.lib"
  1. Clean and Rerun the build. I suspect that it was network failure (ort lib download the static library with build script from Rust)
altunenes commented 3 months ago

Thank you! I solved it with clearing everything and re-install (onnx). The strange thing was that the project I'm working on for my academic project at the moment depends on exactly the same version of Ort and it works, but it didn't work here. I checked with some env variables and solved it.

PS: I hate having to work on a Windows machine 🥲

altunenes commented 3 months ago

out of context: @thewh1teagle by the way, do you plan to use pyannote-rs with sherpa-rs for the transciption or using directly whishper-rs? I just wanted to hear your opinion. :) https://github.com/thewh1teagle/sherpa-rs/blob/main/examples/diarize_whisper.rs

thewh1teagle commented 3 months ago

by the way, do you plan to use pyannote-rs with sherpa-rs for the transciption or using directly whishper-rs? I just wanted to hear your opinion. :)

I plan to use whisper-rs directly. sherpa-rs (onnx) doesn't have enough support for whisper yet and it works much slower even with directml optimization with whisper.

I already added it to vibe. it works amazingly on macOS. But now I encountered the same issue you created here on Windows

log_when_knf-rs_link_dynamic_msvc.txt

Looks like the issues comes from ort

https://github.com/ggerganov/whisper.cpp/issues/2109#issuecomment-2274829722

thewh1teagle commented 3 months ago

Some notes for future

It solved the issue. cargo errors are very confusing and it was diffecult finding the cause. Native libraries such as whisper.cpp / onnxruntime / knf-rs depends on msvc runtime library for core c++ functions In single program the link of all the native libraries should be to the same kind of linking to msvc runtime

In general this is the setting and it should be set on every CmakeLists.txt https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html

If the cmake is old / the config of cmake then the options in the link pasted won't work. knf-rs link msvc static, also onnx. but whisper doens't so that was the issue for me. I ended with custom whisper.cpp cmake file

if (MSVC)
    set(CompilerFlags
            CMAKE_CXX_FLAGS
            CMAKE_CXX_FLAGS_DEBUG
            CMAKE_CXX_FLAGS_RELEASE
            )
    foreach(CompilerFlag ${CompilerFlags})
    string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
    endforeach()
endif()
altunenes commented 3 months ago

"linking" releated errors are probably the most annoying errors in rust. And usually the problem is caused by version incompatibility of different libraries with each other... By the way, I got a different linking error when I tried to test this with sherpa-rs. But as you said, it makes more sense to continue with whisper-rs for now...

altunenes commented 3 months ago

and bingo,

Some notes for future

It solved the issue. cargo errors are very confusing and it was diffecult finding the cause. Native libraries such as whisper.cpp / onnxruntime / knf-rs depends on msvc runtime library for core c++ functions In single program the link of all the native libraries should be to the same kind of linking to msvc runtime

In general this is the setting and it should be set on every CmakeLists.txt https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html

If the cmake is old / the config of cmake then the options in the link pasted won't work. knf-rs link msvc static, also onnx. but whisper doens't so that was the issue for me. I ended with custom whisper.cpp cmake file

if (MSVC)
    set(CompilerFlags
            CMAKE_CXX_FLAGS
            CMAKE_CXX_FLAGS_DEBUG
            CMAKE_CXX_FLAGS_RELEASE
            )
    foreach(CompilerFlag ${CompilerFlags})
    string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
    endforeach()
endif()

And now, I got exactly same error when I try it with whishper-rs hah! I will try your solution now

altunenes commented 3 months ago

Some notes for future

It solved the issue. cargo errors are very confusing and it was diffecult finding the cause. Native libraries such as whisper.cpp / onnxruntime / knf-rs depends on msvc runtime library for core c++ functions In single program the link of all the native libraries should be to the same kind of linking to msvc runtime

In general this is the setting and it should be set on every CmakeLists.txt https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html

If the cmake is old / the config of cmake then the options in the link pasted won't work. knf-rs link msvc static, also onnx. but whisper doens't so that was the issue for me. I ended with custom whisper.cpp cmake file

if (MSVC)
    set(CompilerFlags
            CMAKE_CXX_FLAGS
            CMAKE_CXX_FLAGS_DEBUG
            CMAKE_CXX_FLAGS_RELEASE
            )
    foreach(CompilerFlag ${CompilerFlags})
    string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
    endforeach()
endif()

I'm still encountering the same error after making the changes. Since I have nearly no experience with CMake or Cpp, could you please specify exactly which file I should edit and where to find it in the whisper-rs project structure?

( I assumed I should edit the file at 'target\debug\build\whisper-rs-sys-eed943a0d7bbe2f1\out\whisper.cpp\CMakeLists.txt' and made the changes you recommended. But probably I'm probably on the wrong track). . Thank you for your patience :(

note my cmake version: 3.30.0

thewh1teagle commented 3 months ago

"linking" releated errors are probably the most annoying errors in rust. And usually the problem is caused by version incompatibility of different libraries with each other... By the way, I got a different linking error when I tried to test this with sherpa-rs. But as you said, it makes more sense to continue with whisper-rs for now...

Yes even now I don't fully understand the errors...

I'm still encountering the same error after making the changes. Since I have nearly no experience with CMake or Cpp, could you please specify exactly which file I should edit and where to find it in the whisper-rs project structure?

( I assumed I should edit the file at 'target\debug\build\whisper-rs-sys-eed943a0d7bbe2f1\out\whisper.cpp\CMakeLists.txt' and made the changes you recommended. But probably I'm probably on the wrong track). . Thank you for your patience :(

note my cmake version: 3.30.0

I forgot to mention that you also need to tell cargo to link msvc statically too Set RUSTFLAGS environment variable to -C target-feature=+crt-static (clean and rebuild)

Also for patching whisper you need custom whisper-rs with custom git submodule of whisper.cpp which modified. See https://github.com/thewh1teagle/vibe/blob/feat/diarization-v1/core/Cargo.toml#L12C1-L14C4