Skip to content

Conversation

@rustylocker
Copy link

I'm using libosdp-rs in Zephyr building with GCC (defined __BARE_METAL__, __ZEPHYR__ ).
And I faced the following issues:

  • Duplicated symbol gettimeofday (linker issue) and
  • __noreturn undefined

@sidcha
Copy link
Member

sidcha commented Nov 26, 2025

__ZEPHYR__ and __BARE_METAL__ are mutually exclusive as zephyr is an RTOS. We need to fix the real problem which causes __BARE_METAL__ to be enabled when you build for zephyr. The fix would be 2 parts:

  • Fix why you get __BARE_METAL__ defined
  • Fix platform detection macros to include __ZEPHYR__ so you don't get a duplicate gettimeofday definition (like it is done for linux for example).

I can take a look at this a bit later. But please feel free to investigate it yourself.

@rustylocker
Copy link
Author

In my environment __BARE_METAL__ is defined in build.rs because CARGO_CFG_TARGET_OS is none. Up to the documentation the latter is perfectly normal for embedded devices.

If I define __ZEPHYR__ forcefully (without __BARE_METAL__) the compiler can't find <zephyr/toolchain>.
And when I add zephyr/include to the include directories in build.rs I get the preprocessor error "processor architecture not supported".

warning: libosdp-sys@3.1.0: In file included from /workdir/zephyr/include/zephyr/toolchain.h:52,
warning: libosdp-sys@3.1.0:                  from vendor/utils/include/utils/utils.h:152,
warning: libosdp-sys@3.1.0:                  from vendor/utils/include/utils/slab.h:14,
warning: libosdp-sys@3.1.0:                  from vendor/utils/src/slab.c:11:
warning: libosdp-sys@3.1.0: /workdir/zephyr/include/zephyr/toolchain/gcc.h:622:2: error: #error processor architecture not supported
warning: libosdp-sys@3.1.0:   622 | #error processor architecture not supported
warning: libosdp-sys@3.1.0:       |  ^~~~~
error: failed to run custom build command for `libosdp-sys v3.1.0

Caused by:
  process didn't exit successfully: ... (exit status: 1)
  --- stdout
  cargo:warning=Forced building for Zephyr target
  OPT_LEVEL = Some(z)
  OUT_DIR = Some(...)
  TARGET = Some(thumbv7em-none-eabi)
  CARGO_ENCODED_RUSTFLAGS = Some()
  HOST = Some(x86_64-unknown-linux-gnu)
  cargo:rerun-if-env-changed=CC_thumbv7em-none-eabi
  CC_thumbv7em-none-eabi = None
  cargo:rerun-if-env-changed=CC_thumbv7em_none_eabi
  CC_thumbv7em_none_eabi = Some(/opt/toolchains/zephyr-sdk-0.17.1/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc)
  RUSTC_WRAPPER = None
  cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some(false)
  CARGO_CFG_TARGET_FEATURE = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  cargo:rerun-if-env-changed=TARGET_CFLAGS
  TARGET_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS_thumbv7em_none_eabi
  CFLAGS_thumbv7em_none_eabi = None
  cargo:rerun-if-env-changed=CFLAGS_thumbv7em-none-eabi
  CFLAGS_thumbv7em-none-eabi = None
  cargo:warning=In file included from /workdir/zephyr/include/zephyr/toolchain.h:52,
  cargo:warning=                 from vendor/utils/include/utils/utils.h:152,
  cargo:warning=                 from vendor/utils/include/utils/slab.h:14,
  cargo:warning=                 from vendor/utils/src/slab.c:11:
  cargo:warning=/workdir/zephyr/include/zephyr/toolchain/gcc.h:622:2: error: #error processor architecture not supported
  cargo:warning=  622 | #error processor architecture not supported
  cargo:warning=      |  ^~~~~

  --- stderr

  error occurred in cc-rs: command did not execute successfully (status code exit status: 1): LC_ALL="C" "/opt/toolchains/zephyr-sdk-0.17.1/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc" "-Os" "-ffunction-sections" "-fdata-sections" "-mthumb" "-march=armv7e-m" "-I" "vendor/src" "-I" "vendor/include" "-I" "vendor/utils/include" "-I" ... "-I" "/workdir/zephyr/include" "-Werror" "-Wall" "-Wextra" "-fshort-enums" "-D __ZEPHYR__=1" "-o" ... "-c" "vendor/utils/src/slab.c"

Do you have an idea how to solve this?

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

Successfully merging this pull request may close these issues.

2 participants