Undefined reference error while trying to use out-of-tree driver

I have create small project with a sensor driver that does not exist in main source tree. But when I trying to compile it I have an error undefined reference to `__device_dts_ord_84'.

-- Zephyr version: 3.2.99 (/home/quard/ncs/zephyr), build: v3.2.99-ncs2
[174/184] Linking C executable zephyr/zephyr_pre0.elf
FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map /home/quard/Projects/learn/nRF/si1145_demo/build/zephyr/zephyr_pre0.map 
: && ccache /home/quard/.local/zephyr-sdk-0.15.2/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc  -gdwarf-4 zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr/zephyr_pre0.elf  zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj  -fuse-ld=bfd  -Wl,-T  zephyr/linker_zephyr_pre0.cmd  -Wl,-Map=/home/quard/Projects/learn/nRF/si1145_demo/build/zephyr/zephyr_pre0.map  -Wl,--whole-archive  app/libapp.a  zephyr/libzephyr.a  zephyr/arch/common/libarch__common.a  zephyr/arch/arch/arm/core/aarch32/libarch__arm__core__aarch32.a  zephyr/arch/arch/arm/core/aarch32/cortex_m/libarch__arm__core__aarch32__cortex_m.a  zephyr/lib/libc/minimal/liblib__libc__minimal.a  zephyr/soc/arm/nordic_nrf/nrf52/libsoc__arm__nordic_nrf__nrf52.a  zephyr/drivers/clock_control/libdrivers__clock_control.a  zephyr/drivers/console/libdrivers__console.a  zephyr/drivers/gpio/libdrivers__gpio.a  zephyr/drivers/i2c/libdrivers__i2c.a  zephyr/drivers/sensor/lis2dh/libdrivers__sensor__lis2dh.a  zephyr/drivers/sensor/lis2mdl/libdrivers__sensor__lis2mdl.a  zephyr/drivers/sensor/nrf5/libdrivers__sensor__nrf5.a  zephyr/drivers/sensor/stmemsc/libdrivers__sensor__stmemsc.a  zephyr/drivers/serial/libdrivers__serial.a  zephyr/drivers/timer/libdrivers__timer.a  zephyr/drivers/pinctrl/libdrivers__pinctrl.a  modules/nrf/lib/fatal_error/lib..__nrf__lib__fatal_error.a  modules/hal_nordic/nrfx/libmodules__hal_nordic__nrfx.a  -Wl,--no-whole-archive  zephyr/kernel/libkernel.a  -L"/home/quard/.local/zephyr-sdk-0.15.2/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.1.0/thumb/v7e-m/nofp"  -L/home/quard/Projects/learn/nRF/si1145_demo/build/zephyr  -lgcc  zephyr/arch/common/libisr_tables.a  -no-pie  -mcpu=cortex-m4  -mthumb  -mabi=aapcs  -mfp16-format=ieee  -Wl,--gc-sections  -Wl,--build-id=none  -Wl,--sort-common=descending  -Wl,--sort-section=alignment  -Wl,-u,_OffsetAbsSyms  -Wl,-u,_ConfigAbsSyms  -nostdlib  -static  -Wl,-X  -Wl,-N  -Wl,--orphan-handling=warn && cd /home/quard/Projects/learn/nRF/si1145_demo/build/zephyr && /usr/bin/cmake -E echo
/home/quard/.local/zephyr-sdk-0.15.2/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.1.0/../../../../arm-zephyr-eabi/bin/ld.bfd: app/libapp.a(main.c.obj): in function `main':
/home/quard/Projects/learn/nRF/si1145_demo/src/main.c:23: undefined reference to `__device_dts_ord_84'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /usr/bin/cmake --build /home/quard/Projects/learn/nRF/si1145_demo/build

Based on a error message it seems like driver is not a part of final linkage command and I could not find how to add it. I have checked a few different repositories that implements out-of-tree drivers and they are looks similar for me.

Code available github.com/.../si1145-drv-demo.

Thanks ahead.

Parents
  • Hi  Vadym

    Which version of NCS are you using?

    I downloaded your application and compiled it with NCS 2.3 without any problems. Try to delete your build folder and do a prestine build. 

    Regards

    Runar

  • I have exactly the same version of NCS but I it was updated few times, I believe that initially was installed something like 1.9. Also I noticed that 2.4 was released and try it but result the same.

    Update was done by such set of commands

    git fetch origin
    git checkout v2.3.0
    west update

    I will try to reinstall environment from scratch and will notify if I have any success.

  • I would perhaps recommend using the toolchain manager if you need multiple versions of NCS, but that is more of an personal preference. 

    Try to delete the build folder and do a prestine build before you remove everything. 

    You could also try with an west update inside your 2.3 folder 

    Regards

    Runar

  • Yes, each time before the build I deleted the build folder. And I do not use a few versions of NCS on a machine, just one which I update to the latest version.

  • So, actually I don't have any success, each time the same error. I already tried to reinstall environment on my machines, create docker container with build environment and last try was to install Ubuntu 22.04 in VirtualBox and setup environment in a fresh and clean system.

    Maybe I need some additional arguments for build command.

    Basically I use `west build -b bbc_microbit_v2` command to build the project.

    Bellow you can find dockerfile that creates a build environment that I use.

    FROM ubuntu:22.04
    
    ENV TZ=Europe/Kiev
    ENV USER=ncs
    ENV GROUP=nordic
    
    
    RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
        && echo $TZ > /etc/timezone \
        && apt update \
        && apt install -y wget \
        && wget https://apt.kitware.com/kitware-archive.sh \
        && bash kitware-archive.sh \
        && rm kitware-archive.sh \
        && apt install -y --no-install-recommends \
            git \
            cmake \
            ninja-build \
            gperf \
            ccache \
            dfu-util \
            device-tree-compiler \
            wget \
            python3-dev \
            python3-pip \
            python3-setuptools \
            python3-tk \
            python3-wheel \
            xz-utils \
            file \
            make \
            gcc \
            gcc-multilib \
            g++-multilib \
            libsdl2-dev \
            libmagic1 \
        && groupadd ${GROUP} \
        && useradd -m -s /bin/bash -g ${GROUP} -G sudo ${USER}
    
    USER ${USER}:${GROUP}
    RUN pip3 install --user west \
        && cd /home/${USER} \
        && echo 'export PATH=/home/${USER}/.local/bin:"$PATH"' >> /home/${USER}/.bashrc \
        && export PATH=/home/${USER}/.local/bin:"$PATH" \
        && mkdir ncs \
        && cd ncs \
        && west init -m https://github.com/nrfconnect/sdk-nrf --mr v2.3.0 \
        && west update \
        && west zephyr-export \
        && pip install --user -r zephyr/scripts/requirements.txt \
        && pip install --user -r nrf/scripts/requirements.txt \
        && pip3 install --user -r bootloader/mcuboot/scripts/requirements.txt \
        && cd /home/${USER}/.local \
        && wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.2/zephyr-sdk-0.15.2_linux-x86_64.tar.gz \
        && tar xvf zephyr-sdk-0.15.2_linux-x86_64.tar.gz \
        && cd zephyr-sdk-0.15.2 \
        && ./setup.sh -t all -c \
        && rm /home/${USER}/.local/zephyr-sdk-0.15.2_linux-x86_64.tar.gz \
        && echo 'source /home/${USER}/ncs/zephyr/zephyr-env.sh' >> /home/${USER}/.bashrc

Reply
  • So, actually I don't have any success, each time the same error. I already tried to reinstall environment on my machines, create docker container with build environment and last try was to install Ubuntu 22.04 in VirtualBox and setup environment in a fresh and clean system.

    Maybe I need some additional arguments for build command.

    Basically I use `west build -b bbc_microbit_v2` command to build the project.

    Bellow you can find dockerfile that creates a build environment that I use.

    FROM ubuntu:22.04
    
    ENV TZ=Europe/Kiev
    ENV USER=ncs
    ENV GROUP=nordic
    
    
    RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
        && echo $TZ > /etc/timezone \
        && apt update \
        && apt install -y wget \
        && wget https://apt.kitware.com/kitware-archive.sh \
        && bash kitware-archive.sh \
        && rm kitware-archive.sh \
        && apt install -y --no-install-recommends \
            git \
            cmake \
            ninja-build \
            gperf \
            ccache \
            dfu-util \
            device-tree-compiler \
            wget \
            python3-dev \
            python3-pip \
            python3-setuptools \
            python3-tk \
            python3-wheel \
            xz-utils \
            file \
            make \
            gcc \
            gcc-multilib \
            g++-multilib \
            libsdl2-dev \
            libmagic1 \
        && groupadd ${GROUP} \
        && useradd -m -s /bin/bash -g ${GROUP} -G sudo ${USER}
    
    USER ${USER}:${GROUP}
    RUN pip3 install --user west \
        && cd /home/${USER} \
        && echo 'export PATH=/home/${USER}/.local/bin:"$PATH"' >> /home/${USER}/.bashrc \
        && export PATH=/home/${USER}/.local/bin:"$PATH" \
        && mkdir ncs \
        && cd ncs \
        && west init -m https://github.com/nrfconnect/sdk-nrf --mr v2.3.0 \
        && west update \
        && west zephyr-export \
        && pip install --user -r zephyr/scripts/requirements.txt \
        && pip install --user -r nrf/scripts/requirements.txt \
        && pip3 install --user -r bootloader/mcuboot/scripts/requirements.txt \
        && cd /home/${USER}/.local \
        && wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.15.2/zephyr-sdk-0.15.2_linux-x86_64.tar.gz \
        && tar xvf zephyr-sdk-0.15.2_linux-x86_64.tar.gz \
        && cd zephyr-sdk-0.15.2 \
        && ./setup.sh -t all -c \
        && rm /home/${USER}/.local/zephyr-sdk-0.15.2_linux-x86_64.tar.gz \
        && echo 'source /home/${USER}/ncs/zephyr/zephyr-env.sh' >> /home/${USER}/.bashrc

Children
  • Hi

    I have set up a ubuntu installation now and will try it again and see if I can replicate it

    Runar

  • Quick update, it seems like Zephr tricked me. My build did "fail", or I was able to compile it, however if I checked the build log it stated that it could not enable the SI1145 

     

    warning: SI1145 (defined at /home/rusi/Support/si1145-drv-demo/drivers/sensor/si1145/Kconfig:1) was
    assigned the value 'y' but got the value 'n'. Check these unsatisfied dependencies:
    DT_HAS_SILABS_SI1145_ENABLED (=n). See
    http://docs.zephyrproject.org/latest/kconfig.html#CONFIG_SI1145 and/or look up SI1145 in the
    menuconfig/guiconfig interface. The Application Development Primer, Setting Configuration Values,
    and Kconfig - Tips and Best Practices sections of the manual might be helpful too.

    So my guess is there is something in the devicetree config that needs to be change. Will digg further. 

    Runar

  • I had same error when my Kconfig in project root contains only one line

    rsource "drivers/Kconfig"

    After changes to the current state this error was fixed for me.

  • Hi and sorry for the delay. 

    Can you try the following: 

    In your main project folder to the following:

    1. Add a folder named zephyr

    2. create a file called module.yml

    Insert the following into the module file:

    build:
      cmake: .
      kconfig: Kconfig
      settings:
        dts_root: .

    Update your overlay file with the following:

    // NOTE this is for my 5340. You will need to update the pins to what you want to use
    &i2c1 {
        status = "okay";
        compatible = "nordic,nrf-twim";
        pinctrl-0 = <&i2c1_default>;
    	pinctrl-1 = <&i2c1_sleep>;
    	pinctrl-names = "default", "sleep";
        uvsens: si1145@60 {
            compatible = "silabs,si1145";
            status = "okay";
            reg = < 0x60 >;
        };
    };
    
    Update the line in main.c where you do the following:

    //const struct device *const dev = DEVICE_DT_GET_ANY(silabs_si1145); //old
    const struct device *const dev = DEVICE_DT_GET_ANY(i2c1); //new
    
    Regards

    Runar

  • Project was compiled successfully with given changes. I'm not able to check if code is working on a device, I will do it nearest days and write update here.

    Initial git repository was updated as well.

    Thank you for your help.

Related