Bindgen undefined reference in Rust

I'm trying to link against libwiringPi.so.2.60 which is generated into PathBuf::from(env::current_dir().unwrap().join("..").join("WiringPi").join("wiringPi"));

Entire example:

You can see my build.rs, I link against it:

let lib_path = PathBuf::from(env::current_dir().unwrap().join("..").join("WiringPi").join("wiringPi"));

println!("cargo:rustc-link-search={}", lib_path.display());
println!("cargo:rustc-link-lib=dylib=wiringPi");

Here's the output:

= note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-Wl,--eh-frame-hdr" "-L" "/root/.rustup/toolchains/stable-armv7-unknown-linux-gnueabihf/lib/rustlib/armv7-unknown-linux-gnueabihf/lib" "/home/project/w25qxx_spi/target/debug/deps/w25qxx_spi-c873785913c20cf0.1cyr5fxybvft3qti.rcgu.o" "/home/project/w25qxx_spi/target/debug/deps/w25qxx_spi-c873785913c20cf0.20wfeibehxbnzj5j.rcgu.o" "/home/project/w25qxx_spi/target/debug/deps/w25qxx_spi-c873785913c20cf0.2bdt901unq8kb73r.rcgu.o" "/home/project/w25qxx_spi/target/debug/deps/w25qxx_spi-c873785913c20cf0.3izf55xl9ssviut.rcgu.o" "/home/project/w25qxx_spi/target/debug/deps/w25qxx_spi-c873785913c20cf0.57hzytvmu1dssx8x.rcgu.o" "/home/project/w25qxx_spi/target/debug/deps/w25qxx_spi-c873785913c20cf0.5e9ru8u5t7pkxbs9.rcgu.o" "/home/project/w25qxx_spi/target/debug/deps/w25qxx_spi-c873785913c20cf0.ef2dvkmce1jwqpe.rcgu.o" "/home/project/w25qxx_spi/target/debug/deps/w25qxx_spi-c873785913c20cf0.rq4jb5z1jbtyyru.rcgu.o" "-o" "/home/project/w25qxx_spi/target/debug/deps/w25qxx_spi-c873785913c20cf0" "/home/project/w25qxx_spi/target/debug/deps/w25qxx_spi-c873785913c20cf0.5gs5iww7vdgmfj3t.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "/home/project/w25qxx_spi/target/debug/deps" "-L" "/home/project/w25qxx_spi/../WiringPi/wiringPi" "-L" "/root/.rustup/toolchains/stable-armv7-unknown-linux-gnueabihf/lib/rustlib/armv7-unknown-linux-gnueabihf/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/root/.rustup/toolchains/stable-armv7-unknown-linux-gnueabihf/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/libstd-53c530c298e786e7.rlib" "/root/.rustup/toolchains/stable-armv7-unknown-linux-gnueabihf/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/libpanic_unwind-86b6290c5d7c1fd7.rlib" "/root/.rustup/toolchains/stable-armv7-unknown-linux-gnueabihf/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/libminiz_oxide-94942e22e678c1a5.rlib" "/root/.rustup/toolchains/stable-armv7-unknown-linux-gnueabihf/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/libadler-39dcd84518c30e9b.rlib" "/root/.rustup/toolchains/stable-armv7-unknown-linux-gnueabihf/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/libobject-89e1368bd60f4023.rlib" "/root/.rustup/toolchains/stable-armv7-unknown-linux-gnueabihf/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/libaddr2line-5be2c117cfb7f60d.rlib" "/root/.rustup/toolchains/stable-armv7-unknown-linux-gnueabihf/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/libgimli-34cb9301669fc987.rlib" "/root/.rustup/toolchains/stable-armv7-unknown-linux-gnueabihf/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/librustc_demangle-f43aaf56e9ef969e.rlib" "/root/.rustup/toolchains/stable-armv7-unknown-linux-gnueabihf/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/libhashbrown-91f9a983b8b4a629.rlib" "/root/.rustup/toolchains/stable-armv7-unknown-linux-gnueabihf/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/librustc_std_workspace_alloc-db39d5d90bb45f56.rlib" "/root/.rustup/toolchains/stable-armv7-unknown-linux-gnueabihf/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/libunwind-81c06640c4fa384f.rlib" "/root/.rustup/toolchains/stable-armv7-unknown-linux-gnueabihf/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/libcfg_if-b83eaf4216a8c0da.rlib" "/root/.rustup/toolchains/stable-armv7-unknown-linux-gnueabihf/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/liblibc-8275fa017a5041d9.rlib" "/root/.rustup/toolchains/stable-armv7-unknown-linux-gnueabihf/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/liballoc-23a40b4eca4f2477.rlib" "/root/.rustup/toolchains/stable-armv7-unknown-linux-gnueabihf/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/librustc_std_workspace_core-d8ebf3d408359b72.rlib" "/root/.rustup/toolchains/stable-armv7-unknown-linux-gnueabihf/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/libcore-4e8dd643630741f2.rlib" "-Wl,--end-group" "/root/.rustup/toolchains/stable-armv7-unknown-linux-gnueabihf/lib/rustlib/armv7-unknown-linux-gnueabihf/lib/libcompiler_builtins-346d0172de053d25.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-lutil"

it doesn't even try to link against -lwiringPi.

It currently claims undefined reference for one of libWiringPi.so functions.

What am I doing wrong?

Rust will only pass -lwiringPi when building your library target, on the basis that the binary target should access the API through the library target. So I don't think this line in main.rs will work:

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

how should I use bindings.rs on main.rs then?

It should access the bindings through the API of the library.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.