Skip to content

Commit 7983eb8

Browse files
Copilottwistedfall
andcommitted
Fix cross-compilation by checking sysroot for multiarch paths
When PKG_CONFIG_SYSROOT_DIR is set (cross-compilation scenario), check for OpenCV headers under the sysroot directory first before falling back to host system paths. Co-authored-by: twistedfall <[email protected]>
1 parent 892220e commit 7983eb8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

build/header.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::env;
12
use std::fs::File;
23
use std::io::{BufRead, BufReader};
34
use std::path::{Path, PathBuf};
@@ -131,7 +132,22 @@ pub fn get_multiarch_header_dir() -> Option<PathBuf> {
131132

132133
eprintln!("=== Trying multiarch paths: {try_multiarch:?}");
133134

135+
// Get PKG_CONFIG_SYSROOT_DIR if set (used in cross-compilation scenarios)
136+
let sysroot = env::var_os("PKG_CONFIG_SYSROOT_DIR").map(PathBuf::from);
137+
if let Some(ref sysroot_path) = sysroot {
138+
eprintln!("=== PKG_CONFIG_SYSROOT_DIR is set: {}", sysroot_path.display());
139+
}
140+
134141
for multiarch in try_multiarch {
142+
// Try with sysroot first (for cross-compilation)
143+
if let Some(ref sysroot_path) = sysroot {
144+
let header_dir = sysroot_path.join(format!("usr/include/{multiarch}/opencv4"));
145+
eprintln!("=== Checking sysroot multiarch path: {}", header_dir.display());
146+
if header_dir.is_dir() {
147+
return Some(header_dir);
148+
}
149+
}
150+
// Fallback to host system paths
135151
let header_dir = PathBuf::from(format!("/usr/include/{multiarch}/opencv4"));
136152
if header_dir.is_dir() {
137153
return Some(header_dir);

0 commit comments

Comments
 (0)