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

    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