项目子目录作为Git子模块导致Rust-C++绑定构建失败求助
解决方案
问题根源
错误提示找不到core/cluster.hxx,是因为你给clang的include路径指向了core目录本身,但C++头文件里的引用是#include <core/cluster.hxx>(或类似形式),clang需要从couchbase-cxx-client目录开始查找core子目录,而非直接进入core目录。
修改步骤
调整build.rs中的clang include参数:
修正核心include路径:
将原代码里的:.clang_arg("-I./couchbase-transactions-cxx/deps/couchbase-cxx-client/core")替换为:
.clang_arg("-I./couchbase-transactions-cxx/deps/couchbase-cxx-client")(可选优化)规范头文件引用路径:
将:.clang_arg("-I./couchbase-transactions-cxx/include/couchbase")替换为:
.clang_arg("-I./couchbase-transactions-cxx/include")同时把
headers.h内容改为:#include "couchbase/transactions.hxx"(可选)用绝对路径避免相对路径歧义:
利用你已有的路径规范化代码,确保路径绝对正确:// 在bindgen构建前添加这段代码 let client_root_dir = PathBuf::from("couchbase-transactions-cxx/deps/couchbase-cxx-client"); let client_root_canonical = canonicalize(client_root_dir).unwrap(); let client_include_path = client_root_canonical.to_str().unwrap(); // 替换对应的clang_arg .clang_arg(format!("-I{}", client_include_path))
验证修改
重新执行cargo build,clang即可正确找到core/cluster.hxx及其他依赖头文件。
内容的提问来源于stack exchange,提问作者Sonu
相关产品推荐
相关产品推荐

