Bindgen: Some extern functions couldn’t be found

"Some extern functions couldn't be found; some native libraries may need to be installed or have their path specified"

Help with cargo build and Rust bindgen and custom C/C++ library, on Ubuntu Linux. Native libraries are mpfr, gmp, gmpxx. For purposes of this example, external code has been reduced to two functions, add_long(long i, long j) and add_double(double i, double j).

Note, the generated bindings.rs uses link_name with \u{1} whereas on GitHub the extern C code uses link(name="library_name"). Neither option appears to work!

Keywords:
bindgen
pkg-config
cargo:rustc-link-lib
cargo:rustc-link-search
.header()
.clang_arg()
.clang_args()
.allowlist_function()
.parse_callbacks()
CargoCallbacks
LD_LIBRARY_PATH
gmp
mpfr
library
dynamic
static
Makefile
cargo 1.87.0
rustc 1.87.0

https://github.com/AlexWeslowski/Bindgen-Demo

Your Cargo.toml is malformed.

Updated Cargo.toml

Note I have been able to build this alternative demo (after installing llvm and clang).

Well, yeah, you obviously need a compiler backend for Rust and a Cpp Compiler.

For the problematic project, on Ubuntu the Cpp compiler is optional since the .so file is available on GitHub. Here are the tool versions I'm using:
rustc 1.87.0
g++ 14.2.0

You'd still need a linker to link the sofile, which afaik usually comes with the compiler toolchain.

The problem appears to be related to C++? Without the Cpp compiler/linker flags the bindings will generate fine for C code. Adding the following to Rust-Bindgen-Example build.rs, will cause the same error message, regarding native libraries.
.clang_arg("-xc++")
.clang_arg("-std=c++11")

One of the bindgen maintainers recommended this example!

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.