Cannot find type `_CharT` in this scope (`istream`, `ostream`)
Describe the bug
When generating binding for mfem, I get the error
error[E0412]: cannot find type `_CharT` in this scope
--> /home/trch/software/Rust/Scientific/mfem/target/debug/build/mfem-sys-3857909d484caabf/out/autocxx-build-dir/rs/autocxx-ffi-default-gen.rs:1:1777442
|
1 | ...:: basic_ostream < _CharT > > , } # [repr (C)] pub struct basic_istre...
| ^^^^^^ not found in this scope
|
help: you might be missing a type parameter
The problematic code generated is
pub struct basic_ostream_sentry {
_M_ok: bool,
_M_os: __bindgen_marker_Reference<*mut root::std::basic_ostream<_CharT>>,
}
where _CharT is unbound — elsewhere it is used as a type parameter.
I don't know why autocxx goes so deep into the C++ standard library. It is possible to stop it at a higher level? In fact, i t would be nice if autocxx would already offer a high level Rust interface to istream and ostream.
This behavior starts with version 0.29, prior to that, the bindings are generated fine.
ran into a similar issue when using autocxx on an internal c++ library
error[E0412]: cannot find type `_CharT` in this scope
--> /home/space/repos/export-server/target/debug/build/jt-sys-6b4f046825d821cd/out/autocxx-build-dir/rs/autocxx-ffi-default-gen.rs:1:90593
|
1 | ... type basic_istream_sentry___istream_type = root :: std :: basic_istream < _CharT > ; pub type basic_istream_sentry___ctype_type = root :: std :: basic_istream___ctype_type ; pub t...
| ^^^^^^ not found in this scope
|
help: you might be missing a type parameter
it's working on version 0.27 and broke somewhere after. 0.29 sounds reasonable, so could indeed be it.
potentially also related to https://github.com/rust-lang/rust-bindgen/issues/1051 ?
happy to provide more context if it helps
I'm finding this too, with the same versions - in my case, it's trying to compile https://github.com/leadedge/Spout2 when I generate!() against SpoutReceiver under SpoutReceiver.h - but I don't get this when linking against Spout.h.
The error I get is "Cannot find type _Base in this scope" and "Cannot find type _Traits in this scope"
I'm compiling against the binary SDK version 2.007.2016 (latest as of posting) with the following files:
Cargo.toml
[package]
name = "spout_sys"
version = "0.1.0"
edition = "2024"
[dependencies]
autocxx = "0.30.0"
cxx = "1.0.153"
[build-dependencies]
autocxx-build = "0.30.0"
miette = { version = "5.10.0", features = ["fancy"] }
normpath = "1.3.0"
build.rs
use miette::{miette, IntoDiagnostic};
use normpath::PathExt;
use std::path::PathBuf;
fn main() -> miette::Result<()> {
let b = autocxx_build::Builder::new(
"src/lib.rs",
&[relative("Spout2-2.007.2016/Libs/include/SpoutGL")?],
)
.build()?;
b.compile("spout-bindings");
println!("cargo:rerun-if-changed=src/lib.rs");
let input_files = [
relative("Spout2-2.007.2016/Libs/MD/bin/Spout.dll")?,
relative("Spout2-2.007.2016/Libs/MD/lib/Spout.lib")?,
relative("Spout2-2.007.2016/Libs/MD/bin/SpoutDX.dll")?,
relative("Spout2-2.007.2016/Libs/MD/lib/SpoutDX.lib")?,
];
let out_dir = PathBuf::from(std::env::var("OUT_DIR").into_diagnostic()?);
for f in input_files {
let file_name = f.file_name().ok_or_else(|| miette!("No file_name"))?;
std::fs::copy(&f, out_dir.join(file_name)).unwrap_or_else(|err| {
panic!("Failed to copy {:?} to {:?}: {err}", file_name, &out_dir)
});
}
println!("cargo:rustc-link-lib=dylib=Spout");
println!("cargo:rustc-link-lib=dylib=SpoutDX");
println!("cargo:rustc-link-search=native={:?}", out_dir);
Ok(())
}
fn relative(s: &str) -> miette::Result<PathBuf> {
let result = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
Ok(result
.join(s)
.normalize()
.into_diagnostic()?
.into_path_buf())
}
lib.rs
#![allow(unsafe_op_in_unsafe_fn)]
use autocxx::prelude::*;
include_cpp! {
#include "SpoutReceiver.h"
generate!("SpoutReceiver")
}
pub use ffi::*;
pub use ffi::{make_string, ToCppString};
Worth an extra note: Building/linking against SpoutLibrary seems to work fine, and that doesn't perform any includes against other spout libraries - it's a minimal compatible header, and autocxx seems to handle it fine (though to use it you need to add it and link against it within the build.rs, instead of Spout or SpoutDX)
This behavior starts with version 0.29, prior to that, the bindings are generated fine.
I have the same issue. Using 0.28 works correctly.