-
Hey everyone, I'm struggling a bit getting bindgen to pick up on The files: // wrapper.h
#include "stdio.h" // I have also tried <stdio.h> // build.rs
fn main() {
const HEADER_PATH: &str = "wrapper.h";
println!("cargo:rerun-if-changed={HEADER_PATH}");
let bindings = bindgen::Builder::default()
.header(HEADER_PATH)
.clang_args(["-x", "c", "-std=c11"]) // I have tried with and without that,
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("couldn't write bindings");
} Running either of the below works fine: $ clang wrapper.h
$ bindgen wrapper.h But running
Both Does anyone have any suggestions? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
After some chasing down, it seems like it's due to my target. Running clang with |
Beta Was this translation helpful? Give feedback.
-
Apple Silicon M2 Max, MacOS Sonoma 14.3.1, Xcode-15.2, Rust-1.76.0.
// build.rs
use std::env;
use std::path::PathBuf;
fn main() {
// Tell cargo to look for shared libraries in the specified directory
println!("cargo:rustc-link-search=/opt/local/lib");
// Tell cargo to tell rustc to link the system bzip2
// shared library.
println!("cargo:rustc-link-lib=bz2");
// The bindgen::Builder is the main entry point
// to bindgen, and lets you build up options for
// the resulting bindings.
let bindings = bindgen::Builder::default()
// The input header we would like to generate
// bindings for.
.header("wrapper.h")
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
// Finish the builder and generate the bindings.
.generate()
// Unwrap the Result and panic on failure.
.expect("Unable to generate bindings");
// Write the bindings to the $OUT_DIR/bindings.rs file.
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
} // wrapper.h
#include <bzlib.h> # Cargo.toml
[package]
name = "bindgen-tst2"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
env = "0.0.0"
[build-dependencies]
bindgen = "0.69.4" |
Beta Was this translation helpful? Give feedback.
-
UpdateMoving // wrapper.h
#include <stdio.h>
#include <bzlib.h> // build.rs
use std::env;
use std::path::PathBuf;
fn main() {
// Tell cargo to look for shared libraries in the specified directory
println!("cargo:rustc-link-search=/opt/local/lib");
// Tell cargo to tell rustc to link the system bzip2
// shared library.
println!("cargo:rustc-link-lib=bz2");
// The bindgen::Builder is the main entry point
// to bindgen, and lets you build up options for
// the resulting bindings.
let bindings = bindgen::Builder::default()
// The input header we would like to generate
// bindings for.
.header("wrapper.h")
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
// Finish the builder and generate the bindings.
.generate()
// Unwrap the Result and panic on failure.
.expect("Unable to generate bindings");
// Write the bindings to the $OUT_DIR/bindings.rs file.
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
} Reproduces the failure: $ bindgen wrapper.h -- -v
clang version 16.0.6
Target: arm64-apple-darwin23.3.0
Thread model: posix
InstalledDir:
ignoring nonexistent directory "lib/clang/16/include"
ignoring nonexistent directory "/usr/include"
ignoring duplicate directory "/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/opt/local/libexec/llvm-16/lib/clang/16/include
/System/Library/Frameworks
/Library/Frameworks
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
wrapper.h:3:10: fatal error: 'stdio.h' file not found
panicked at /Users/ur20980/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bindgen-cli-0.69.4/main.rs:52:36:
Unable to generate bindings: ClangDiagnostic("wrapper.h:3:10: fatal error: 'stdio.h' file not found\n")
$
$ port select clang
Available versions for clang:
apple-clang
mp-clang-16
mp-clang-17 (active)
none
$ Observations:
Update 2I found two workarounds:
I still think |
Beta Was this translation helpful? Give feedback.
After some chasing down, it seems like it's due to my target. Running clang with
-target thumbv7em-none-eabihf
gets the same results