undeflife / libreoffice-rs

Rust binding to LibreOfficeKit
Apache License 2.0
15 stars 7 forks source link

Using the library in an application #1

Closed yveszoundi closed 2 years ago

yveszoundi commented 2 years ago

Out of the box, it doesn't seem possible to link against libreoffice-rs. Just adding libreoffice-rs= "0.2.0" in a cargo manifest file results into several compilation errors.

Test environments

Void Linux (Rolling release, amd64)

Many common dev tools are installed, including the following:

Ubuntu Linux Jammy (22.04, amd64)

Many common dev tools are installed, including the following:

How to reproduce

A sample test repository can be found at https://github.com/yveszoundi/libreoffice-rs-tests

Additional information

By default, the build will not be able to find the wrapper library, possibly due to relative path issues I think. I "suspect" that via some cargo environment variables it should be possible to setup expected file/libraries locations.

   Compiling libreoffice-rs v0.2.0
error: linking with `cc` failed: exit status: 1
  |
  = note: "cc"
  "-Wl,--version-script=/tmp/rustcNVyWKz/list"
  "-m64"
  "/home/vip/Projects/officetests/target/debug/deps/libreoffice_rs-e14a1aa6f0f02069.libreoffice_rs.a5ff31e1-cgu.0.rcgu.o"
  "/home/vip/Projects/officetests/target/debug/deps/libreoffice_rs-e14a1aa6f0f02069.libreoffice_rs.a5ff31e1-cgu.1.rcgu.o"
  "/home/vip/Projects/officetests/target/debug/deps/libreoffice_rs-e14a1aa6f0f02069.libreoffice_rs.a5ff31e1-cgu.10.rcgu.o"
  "/home/vip/Projects/officetests/target/debug/deps/libreoffice_rs-e14a1aa6f0f02069.libreoffice_rs.a5ff31e1-cgu.11.rcgu.o"
  "/home/vip/Projects/officetests/target/debug/deps/libreoffice_rs-e14a1aa6f0f02069.libreoffice_rs.a5ff31e1-cgu.12.rcgu.o"
  "/home/vip/Projects/officetests/target/debug/deps/libreoffice_rs-e14a1aa6f0f02069.libreoffice_rs.a5ff31e1-cgu.13.rcgu.o"
  "/home/vip/Projects/officetests/target/debug/deps/libreoffice_rs-e14a1aa6f0f02069.libreoffice_rs.a5ff31e1-cgu.14.rcgu.o"
  "/home/vip/Projects/officetests/target/debug/deps/libreoffice_rs-e14a1aa6f0f02069.libreoffice_rs.a5ff31e1-cgu.15.rcgu.o"
  "/home/vip/Projects/officetests/target/debug/deps/libreoffice_rs-e14a1aa6f0f02069.libreoffice_rs.a5ff31e1-cgu.2.rcgu.o"
  "/home/vip/Projects/officetests/target/debug/deps/libreoffice_rs-e14a1aa6f0f02069.libreoffice_rs.a5ff31e1-cgu.3.rcgu.o"
  "/home/vip/Projects/officetests/target/debug/deps/libreoffice_rs-e14a1aa6f0f02069.libreoffice_rs.a5ff31e1-cgu.4.rcgu.o"
  "/home/vip/Projects/officetests/target/debug/deps/libreoffice_rs-e14a1aa6f0f02069.libreoffice_rs.a5ff31e1-cgu.5.rcgu.o"
  "/home/vip/Projects/officetests/target/debug/deps/libreoffice_rs-e14a1aa6f0f02069.libreoffice_rs.a5ff31e1-cgu.6.rcgu.o"
  "/home/vip/Projects/officetests/target/debug/deps/libreoffice_rs-e14a1aa6f0f02069.libreoffice_rs.a5ff31e1-cgu.7.rcgu.o"
  "/home/vip/Projects/officetests/target/debug/deps/libreoffice_rs-e14a1aa6f0f02069.libreoffice_rs.a5ff31e1-cgu.8.rcgu.o"
  "/home/vip/Projects/officetests/target/debug/deps/libreoffice_rs-e14a1aa6f0f02069.libreoffice_rs.a5ff31e1-cgu.9.rcgu.o"
  "/home/vip/Projects/officetests/target/debug/deps/libreoffice_rs-e14a1aa6f0f02069.hpv62lg5kcs7hfp.rcgu.o"
  "-Wl,--as-needed"
  "-L"
  "/home/vip/Projects/officetests/target/debug/deps"
  "-L"
  "/home/vip/Projects/officetests/target/debug/build/libreoffice-rs-9e286f276340b73e/out"
  "-L"
  "/home/vip/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib"
  "-Wl,-Bstatic"
  "-Wl,--whole-archive"
  "-lwrapper"
  "-Wl,--no-whole-archive"
  "-Wl,--start-group"
  "/home/vip/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-8d61b92a0a02f53a.rlib"
  "/home/vip/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-fc45202bb435016b.rlib"
  "/home/vip/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-f2400674c7513725.rlib"
  "/home/vip/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-605c3a7d1a5d300d.rlib"
  "/home/vip/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-3d4fb4efa907e4e8.rlib"
  "/home/vip/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-65207f030ab23308.rlib"
  "/home/vip/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-76ca199cb0186109.rlib"
  "/home/vip/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-1e3e01ed4f561dc1.rlib"
  "/home/vip/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-dd8dddcba7c13fee.rlib"
  "/home/vip/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-00b13d31c3420656.rlib"
  "/home/vip/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-e4c8460b81557bd5.rlib"
  "/home/vip/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-600d46e5f0005455.rlib"
  "/home/vip/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-e4a08a2585b62d37.rlib"
  "/home/vip/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-fbc21ec567cb9dc7.rlib"
  "/home/vip/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-10b3fa8e49bd978f.rlib"
  "/home/vip/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-64625b73694ffce7.rlib"
  "/home/vip/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-fb6b78ac543a58ee.rlib"
  "/home/vip/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-1d1f2d1bec6f51b8.rlib"
  "-Wl,--end-group"
  "/home/vip/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-acf5ff6e9595d982.rlib"
  "-Wl,-Bdynamic"
  "-lgcc_s"
  "-lutil"
  "-lrt"
  "-lpthread"
  "-lm"
  "-ldl"
  "-lc"
  "-Wl,--eh-frame-hdr"
  "-Wl,-znoexecstack"
  "-L"
  "/home/vip/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib"
  "-o"
  "/home/vip/Projects/officetests/target/debug/deps/liblibreoffice_rs-e14a1aa6f0f02069.so"
  "-Wl,--gc-sections"
  "-shared"
  "-Wl,-zrelro,-znow"
  "-nodefaultlibs"
  = note: /bin/ld: cannot find -lwrapper
          collect2: error: ld returned 1 exit status

error: could not compile `libreoffice-rs` due to previous error

Workaround

The only way for me to test the library was the following:

  1. Build libreoffice-rs separately: LO_INCLUDE_PATH=/usr/include/LibreOfficeKit cargo build
  2. Then link the relative crate path to my project in Cargo.toml: libreoffice-rs = { path = "../libreoffice-rs" }
undeflife commented 2 years ago

I can not reproduce this on my macOs and debian bullseye . Could your provide more details about your environment like your os version 、cargo version etc

I "suspect" that via some cargo environment variables it should be possible to setup expected file/libraries locations.

cargo will deal this part when using OUT_DIR see cargo-build-scripts

yveszoundi commented 2 years ago

Thanks for the prompt response, I updated the bug description to describe the test environments (Ubuntu and Void Linux).

I also created a git repository with a basic project for reproducing the issue: https://github.com/yveszoundi/libreoffice-rs-tests

Please let me know if more information is needed or if I doing something fundamentally wrong.

undeflife commented 2 years ago

I figured this out finally, if your first build failed, usually LibreOfficeKit header files not exists in search path, this error is ignored,so bindings.rs will generated, then whatever you change LO_INCLUDE_PATH, build.rs will not invoked any more. Before this issue get fixed you can run cargo clean and try to build again .