clang_arg don't work when used to include the header file #2418
-
I defined bindgen as follows: let wasm_bindings = bindgen::Builder::default()
// The input header we would like to generate
// bindings for.
.header("../../wasm-runtime/include/bpf-api.h")
.clang_arg("-I")
.clang_arg("../../third_party/wasm-micro-runtime/core/iwasm/include/wasm_export.h")
.clang_arg("-x")
.clang_arg("c++")
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
// Finish the builder and generate the bindings.
.generate()
// Unwrap the Result and panic on failure.
.expect("Unable to generate wasm-bpf bindings"); In the header file The following error occurred in the terminal: --- stderr
../../wasm-runtime/include/bpf-api.h:16:10: fatal error: 'wasm_export.h' file not found
thread 'main' panicked at 'Unable to generate wasm-bpf bindings: ClangDiagnostic("../../wasm-runtime/include/bpf-api.h:16:10: fatal error: 'wasm_export.h' file not found\n")', build.rs:43:10
stack backtrace:
0: rust_begin_unwind
at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:575:5
1: core::panicking::panic_fmt
at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/panicking.rs:64:14
2: core::result::unwrap_failed
at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/result.rs:1791:5
3: core::result::Result<T,E>::expect
4: build_script_build::main
5: core::ops::function::FnOnce::call_once
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
make: *** [Makefile:7: build] Error 101 I also tried defining I wonder know why doesn't clang_arg work? Any advice would be greatly appreciated. (I tried to find related issues, but it didn't solve my problem.) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I think that's because
Or you could use the let wasm_bindings = bindgen::Builder::default()
// The input header we would like to generate
// bindings for.
.header("../../wasm-runtime/include/bpf-api.h")
.header("../../third_party/wasm-micro-runtime/core/iwasm/include/wasm_export.h")
.clang_arg("-x")
.clang_arg("c++")
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
// Finish the builder and generate the bindings.
.generate()
// Unwrap the Result and panic on failure.
.expect("Unable to generate wasm-bpf bindings"); Let me know if this fixes your problem. |
Beta Was this translation helpful? Give feedback.
Yeah that's expected. The issue is that
-include
actually includes the file you pass to it instead of just telling C that the file is available somewhere. Basically doing-include long_path
is the same as putting#include "long_path"
at the top of your headers. When you do-I long_path
this tells the compiler thatlong_path
is one of the directories where it should search for headers.So you have two options:
#include
from your headers and pass-include
.-I
with the directory.