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 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.

  • So, still no success with a sensor driver.

    With i2c1 as a device compat code is compiled but DEVICE_DT_GET_ANY returns NULL.

    *** Booting Zephyr OS build v3.2.99-ncs2 ***
    Hello World! bbc_microbit_v2
    Failed to get device binding

    As soon as I change compat to the sensor value I got the same error as it was before.

    [3/11] 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:30: undefined reference to `__device_dts_ord_88'
    collect2: error: ld returned 1 exit status
    

    Also I have replace __ASSERT macros with ifs because it seems like they are doesn't work at least I don't get the error.

  • So I tested with your code and changed to 

    "const struct device *const dev = DEVICE_DT_GET_ANY(DT_NODELABEL(uvsens));"
    And that compiles for the BBC Micro board. 
    Could you try that and see if you can detect the sensor?
    Runar
Reply Children
Related