“cstdarg file not found” when running jextract on the C binding for a Rust project

旧巷老猫 提交于 2020-12-13 03:25:54

问题


I'm trying to get a simple integer addition function written in Rust working with Java's Project Panama. Having generated the bindings using cbindgen crate, I get the following error when running jextract:

jextract -t org.adder -L . -l adder-java --record-library-path -I /Library/Developer/CommandLineTools/usr/include/c++/v1/cstdarg bindings.h -o adder-java.jar
java.lang.RuntimeException: /Users/ash/Code/adder/bindings.h:1:10: fatal error: 'cstdarg' file not found

I've looked at the examples given, but can't decipher what I'm getting wrong.

Here is my library file:

#[no_mangle]
pub extern "C" fn addition(a: u32, b: u32) -> u32 {
    a + b
}

And the generated bindings (will also need sources for cstdint, cstdlib and new I presume?):

#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 to get jextract to find these files?


回答1:


The correct command is jextract -C -x -C c++ -I /Library/Developer/CommandLineTools/usr/include/c++/v1 -t adder -o adder.jar bindings.h.

Pass -x c++ to clang, include the path specified by -I.



来源:https://stackoverflow.com/questions/62760145/cstdarg-file-not-found-when-running-jextract-on-the-c-binding-for-a-rust-proje

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!