LaurentMazare / diffusers-rs

An implementation of the diffusers api in Rust
Apache License 2.0
521 stars 54 forks source link

Cannot link when used together with cxx-qt crate #73

Closed mneilly closed 1 year ago

mneilly commented 1 year ago

I'm trying to build a simple Qt gui that uses diffusers-rs. I can compile and run both the diffusers example and my cxx-qt gui app separately but when adding both cxx-qt and diffusers in Cargo.toml linking fails.

As a test, I modified the diffusers Cargo.toml as follows with no other changes:

$ git diff Cargo.toml
diff --git a/Cargo.toml b/Cargo.toml
index db4b4d3..70dce57 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -17,6 +17,9 @@ exclude = [
 ]

 [dependencies]
+cxx = "1.0"
+cxx-qt = "0.5"
+cxx-qt-lib = "0.5"
 anyhow = "1"
 thiserror = "1"
 regex = "1.6.0"
@@ -48,3 +51,6 @@ doc-only = ["tch/doc-only"]

 [package.metadata.docs.rs]
 features = ["doc-only"]
+
+[build-dependencies]
+cxx-qt-build = "0.5"

which resulted in the following error:

= note: /usr/bin/ld: /home/mneilly/RustProjects/third_party/DL/diffusers-rs/target/debug/deps/libtorch_sys-34524f8ee2d3acbe.rlib(torch_api_generated.o): undefined reference to symbol '_ZN3c104warnERKNS_7WarningE' /usr/bin/ld: /home/mneilly/RustProjects/sandboxes/tch-sandbox/pytorch-2.0/lib/python3.11/site-packages/torch/lib/libc10.so: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status
= note: some extern functions couldn't be found; some native libraries may need to be installed or have their path specified = note: use the -l flag to specify native libraries to link = note: use the cargo:rustc-link-lib directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname) error: could not compile diffusers (example "stable-diffusion") due to previous error

Note that leaving out cxx-qt-lib causes the linker error to go away.

I've attached the full output from the build.

diffqt.log

mneilly commented 1 year ago

Sorry, turns out I had an old version of torch installed on the system. After removing it I was able to build.