Questions tagged [rust-bindgen]

44 questions
7
votes
1 answer

Seeing bzlib.h not found when trying the Bindgen tutorial

I know there is a similar post to this but I followed it and I'm still seeing the issue so I thought I'd ask again sorry. I downloaded the bbindgen-tutorial-bzip2-sys and tried to run it but I get the following error wrapper.h:1:10: fatal error:…
fmc5046
  • 73
  • 1
  • 1
  • 4
6
votes
0 answers

Undefined symbols with rust-bindgen, but able to compile with cc

I am trying to use rust-bindgen to be able to call glfw and OpenGL functions. bindgen generates the bindings correctly, however, when I actually build my project, it gives me undefined symbols errors (I am running macOS 10.15.3 btw). This would seem…
David Sullivan
  • 462
  • 7
  • 16
5
votes
4 answers

How to get the size of a struct field in Rust without instantiating it

I have a structure with a byte array in it. This structure actually comes from the FFI bindings produced by bindgen, and its size is defined in C code using a macro, i.e.: C code: #define FOO_SIZE 100 struct the_struct { char foo[FOO_SIZE]; …
Roman Dmitrienko
  • 3,375
  • 3
  • 37
  • 48
5
votes
1 answer

How to properly wrap a C function pointer in Rust?

I have a C struct Foo with a function pointer. In my Rust bindings, I would like to allow users to set this function pointer, but I would like to avoid users having to deal with FFI types. foo.h struct Foo { void* internal; uint8_t a; void…
Shoaib Ahmed
  • 424
  • 2
  • 9
3
votes
1 answer

Rust bindgen ignore include specific include from header file

I have a header file lets say greetings.h: include ; include ; include ; ... Im using bindgen in rust to generate those file from c header to rust. But I want to ignore generating the include header and generate the…
3
votes
1 answer

Problems linking header files with Rust bindgen

According to the Rust bindgen tutorial at https://rust-lang.github.io/rust-bindgen/tutorial-3.html, I am trying to generate the FFI for existing C header files. However, I am having trouble linking the header files. The repository at…
studersi
  • 1,345
  • 1
  • 12
  • 14
2
votes
1 answer

How to work with std_vector produced by rust bindgen

I have an external C++ library that I want to use from rust. For this I use bindgen to map the function calls. The C++ function I want to use fills a (C++) string vector and has the signature: short REQ_MList(std::vector *list) Bindgen…
2
votes
2 answers

Local crate not found when trying to update edition via cargo fix

Context: I have a local C library called 'libmaths' that then uses Bindgen to create a 'libmaths-sys' crate that is locally stored in the same directory as my project. Issue: I want to use some of the features in the 2021 edition of Rust and…
Jambalaya
  • 31
  • 4
2
votes
1 answer

How to send a pointer to another thread?

I created a Rust wrapper for a C++ library for a camera using bindgen, and the camera handle in the C++ library is defined as typedef void camera_handle which bindgen ported over as: pub type camera_handle = ::std::os::raw::c_void; I'm able to…
EmaadP
  • 160
  • 1
  • 1
  • 10
2
votes
0 answers

rust bindgen unaligned tcache chunk error

I am working on binding for the avahi lib in rust, and I am encountering a runtime error: malloc(): unaligned tcache chunk detected the code at fault: pub fn register_service( &mut self, name: String, svc_type:…
Le Marin
  • 135
  • 1
  • 12
2
votes
0 answers

Is there a good way to debug CBindgen usage in my build.rs?

My build.rs script is failing in my CI pipeline (Azure Pipelines), but running it locally is working fine. I specifically know I'm failing to generate my cbindgen header, but the error message is just listing files it parsed and not really saying…
ZachChilders
  • 415
  • 3
  • 15
2
votes
2 answers

How do I convert a C-style enum generated by bindgen to another enum?

I am creating bindings in Rust for a C library and Bindgen generated enums like: // Rust #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum rmw_qos_history_policy_t { RMW_QOS_POLICY_HISTORY_SYSTEM_DEFAULT = 0, …
deb0ch
  • 1,133
  • 2
  • 16
  • 25
1
vote
0 answers

Rust compilation failed: I got ld: failed to convert GOTPCREL relocation; relink with --no-relax

I want to use rust-mbedtls in my no-std rust project. But, in no_std without libc, I need to provide my own version of the standard C function calloc()/free() Therefore, I wrote my rust version calloc()/free() as showed in the following so that…
yaoxin jing
  • 55
  • 1
  • 4
1
vote
1 answer

Rust/bindgen - Unable to locate IOKit header files on macOS Ventura

I am attempting to fetch hardware information on macOS using IOKit FFI bindings in rust. I am on a apple silicon machine running macOS 13.1, apple clang 14.0.0, xcode 14.2, and command line tools 14.2. I have reinstalled both xcode and command line…
curlin
  • 21
  • 4
1
vote
1 answer

Bindgen failing because of relative paths in header file

I'm trying to build out some bindings for vmaf but i've been running into some issues. The header files and the .c files in the vmaf repository live in seperate folders. I'm having an issue where the main vmaf.h file references other .h files in the…
Brandon Piña
  • 614
  • 1
  • 6
  • 20
1
2 3