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.

  • 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

Related