I want to use Project Panama's jextract tool to build a Java binding to a Rust library. When running the following command, I get an error:
jextract -C -x -C c++ -I /Library/Developer/CommandLineTools/usr/include/c++/v1 -t adder -o adder.jar bindings.h
java.lang.RuntimeException: /Library/Developer/CommandLineTools/usr/include/c++/v1/stdlib.h:93:15: fatal error: 'stdlib.h' file not found
I'm confused because the include path contains stdlib.h:
ls /Library/Developer/CommandLineTools/usr/include/c++/v1/ | grep stdlib
cstdlib
stdlib.h
The line in error contains only #include_next <stdlib.h>.
My Rust source is a simple function:
#[no_mangle]
pub extern "C" fn addition(a: u32, b: u32) -> u32 {
a + b
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn adds() {
assert_eq!(addition(1, 2), 3);
}
}
The bindings.h header is generated by the cbindgen crate:
#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <new>
extern "C" {
uint32_t addition(uint32_t a, uint32_t b);
} // extern "C"
What do I need to do for jextract to locate stdlib.h?
This was a case of missing an include path - I needed to include the MacOS SDK stdlib.h header file location also. This wasn't clear from the error.
The correct command to have run was:
jextract -C -x -C c++ -I /Library/Developer/CommandLineTools/usr/include/c++/v1 -I /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -t adder -o adder.jar bindings.h
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With