Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when cross compiling: 'sys/time.h' file not found #113

Closed
kkettinger opened this issue Sep 19, 2024 · 8 comments
Closed

Error when cross compiling: 'sys/time.h' file not found #113

kkettinger opened this issue Sep 19, 2024 · 8 comments

Comments

@kkettinger
Copy link

kkettinger commented Sep 19, 2024

When cross compiling my project to armv7-unknown-linux-gnueabihf the v4l2-sys-mit crate throws an error:

   Compiling bindgen v0.65.1
   Compiling v4l2-sys-mit v0.3.0
error: failed to run custom build command for `v4l2-sys-mit v0.3.0`

Caused by:
  process didn't exit successfully: `/workspace/target/debug/build/v4l2-sys-mit-e44acd57c82a0379/build-script-build` (exit status: 101)
  --- stderr
  /usr/include/linux/videodev2.h:60:10: fatal error: 'sys/time.h' file not found
  thread 'main' panicked at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/v4l2-sys-mit-0.3.0/build.rs:10:10:
  Failed to generate bindings: ClangDiagnostic("/usr/include/linux/videodev2.h:60:10: fatal error: 'sys/time.h' file not found\n")
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The sys/time.h file exists:

  • /usr/include/x86_64-linux-gnu/sys/time.h
  • /usr/arm-linux-gnueabihf/include/sys/time.h

Compiling the project directly on the target works. Any idea what could be wrong or missing?

@MarijnS95
Copy link
Collaborator

MarijnS95 commented Sep 19, 2024

If anything it looks like bindgen isn't picking the right header here: /usr/include/linux/videodev2.h:60:10: fatal error: 'sys/time.h' file not found should probably be taking the videodev2.h file from the sysroot at /usr/arm-linux-gnueabihf/include/linux/videodev2.h instead. Perhaps your cross-compliation CFLAGS_armv7-unknown-linux-gnueabihf and/or BINDGEN_EXTRA_CLANG_ARGS_armv7-unknown-linux-gnueabihf aren't set up correctly to use the right sysroot?

@MarijnS95
Copy link
Collaborator

MarijnS95 commented Sep 19, 2024

This target builds successfully for me, even without this header.

Are you perhaps building this on FreeBSD? We introduced a broken hack in #106 (and I approved it 🙈) that should have used environment variables to detect the target for cross-compilation instead of the target that the build script is compiled for.
EDIT: In that case the path in the error should've included /local which it doesn't.

@kkettinger
Copy link
Author

kkettinger commented Sep 19, 2024

I'm building in a debian based vscode devcontainer (mcr.microsoft.com/devcontainers/rust:1-1-bullseye) under docker with windows as host system. Target is a raspberry pi.

$ clang --version
Debian clang version 11.0.1-2
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

@kkettinger
Copy link
Author

Building it on a native debian machine works without errors.. hmm...

@kkettinger
Copy link
Author

Updating the devcontainer to the latest version (with clang 14) solved the issue for me:

- "image": "mcr.microsoft.com/devcontainers/rust:1-1-bullseye",
+ "image": "mcr.microsoft.com/devcontainers/rust:latest",

@MarijnS95 MarijnS95 closed this as not planned Won't fix, can't repro, duplicate, stale Sep 19, 2024
@kkettinger
Copy link
Author

I just had the same issue when building v4l2-sys-mit under Yocto with the meta-rust meta-layer. The problem is that bindgen/clang for the v4l2-sys-mit crate is missing the include path for the recipes sysroot. It then uses the hosts include path, which is wrong in the case of yocto, as yocto prepares a sysroot for the recipe with all dependencies. The path looks like this: /build/tmp/work/cortexa7t2hf-neon-vfpv4-demo-linux-gnueabi/demo-app/1.0+git/recipe-sysroot-native/usr/include/.

The solution (for everyone having the same issue) is setting the CPATH variable for clang in the recipe:

export CPATH = "${STAGING_DIR_TARGET}/usr/include"

If libclang can't be found, also set LIBCLANG_PATH:

export LIBCLANG_PATH = "${STAGING_DIR_NATIVE}${libdir}"

@molysgaard
Copy link

I've found this snippet to help a lot getting crates that use bindgen to compile correctly under bitbake/yocto.

BINDGEN_EXTRA_CLANG_ARGS = "--sysroot=${STAGING_DIR_TARGET}"
export BINDGEN_EXTRA_CLANG_ARGS

@kkettinger
Copy link
Author

I've found this snippet to help a lot getting crates that use bindgen to compile correctly under bitbake/yocto.

BINDGEN_EXTRA_CLANG_ARGS = "--sysroot=${STAGING_DIR_TARGET}"
export BINDGEN_EXTRA_CLANG_ARGS

Great, this works perfectly. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants