Building Blinky project gives me a linker error.

I was folowing the toturial on the DevAcademy nRF Connect SDK Fundamentals, where we would build a simple led blinky software.Everything was going well until we had to compile the program (it was almost too good to be true that it would work on the first try). 

After examining the output of Cmake, I notice that some paths for the header and source files are missing as the linker could not resolve some symbols.

Output of the build:

[1/13] Building C object CMakeFiles/app.dir/src/main.c.obj
FAILED: CMakeFiles/app.dir/src/main.c.obj
C:\ncs\toolchains\v2.2.99-dev3\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe -DKERNEL -DNRF52840_XXAA -DUSE_PARTITION_MANAGER=0 -D__PROGRAM_START -D__ZEPHYR__=1 -IC:/ncs/v2.2.99-dev3/zephyr/include -Izephyr/include/generated -IC:/ncs/v2.2.99-dev3/zephyr/soc/arm/nordic_nrf/nrf52 -IC:/ncs/v2.2.99-dev3/zephyr/soc/arm/nordic_nrf/common/. -IC:/ncs/v2.2.99-dev3/nrf/include -IC:/ncs/v2.2.99-dev3/nrf/tests/include -IC:/ncs/v2.2.99-dev3/modules/hal/cmsis/CMSIS/Core/Include -IC:/ncs/v2.2.99-dev3/modules/hal/nordic/nrfx -IC:/ncs/v2.2.99-dev3/modules/hal/nordic/nrfx/drivers/include -IC:/ncs/v2.2.99-dev3/modules/hal/nordic/nrfx/mdk -IC:/ncs/v2.2.99-dev3/zephyr/modules/hal_nordic/nrfx/. -isystem C:/ncs/v2.2.99-dev3/zephyr/lib/libc/minimal/include -isystem c:/ncs/toolchains/v2.2.99-dev3/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.1.0/include -isystem c:/ncs/toolchains/v2.2.99-dev3/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.1.0/include-fixed -isystem C:/ncs/v2.2.99-dev3/nrfxlib/crypto/nrf_cc310_platform/include -fno-strict-aliasing -Og -imacros C:/ncs/workfolder/my_firstapp/build/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfp16-format=ieee --sysroot=C:/ncs/toolchains/v2.2.99-dev3/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi -imacros C:/ncs/v2.2.99-dev3/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-pic -fno-pie -fno-asynchronous-unwind-tables -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map=C:/ncs/workfolder/my_firstapp=CMAKE_SOURCE_DIR -fmacro-prefix-map=C:/ncs/v2.2.99-dev3/zephyr=ZEPHYR_BASE -fmacro-prefix-map=C:/ncs/v2.2.99-dev3=WEST_TOPDIR -ffunction-sections -fdata-sections -std=c99 -nostdinc -MD -MT CMakeFiles/app.dir/src/main.c.obj -MF CMakeFiles\app.dir\src\main.c.obj.d -o CMakeFiles/app.dir/src/main.c.obj -c ../src/main.c
In file included from C:\ncs\v2.2.99-dev3\zephyr\include\zephyr\toolchain\gcc.h:89,
from C:\ncs\v2.2.99-dev3\zephyr\include\zephyr\toolchain.h:50,
from C:\ncs\v2.2.99-dev3\zephyr\include\zephyr\kernel_includes.h:19,
from C:\ncs\v2.2.99-dev3\zephyr\include\zephyr\kernel.h:17,
from c:\ncs\workfolder\my_firstapp\src\main.c:7:
C:\ncs\v2.2.99-dev3\zephyr\include\zephyr\device.h:83:41: error: '__device_dts_ord_DT_N_ALIAS_led0_P_gpios_IDX_0_PH_ORD' undeclared here (not in a function)
83 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
| ^~~~~~~~~
C:\ncs\v2.2.99-dev3\zephyr\include\zephyr\toolchain\common.h:132:26: note: in definition of macro '_DO_CONCAT'
132 | #define _DO_CONCAT(x, y) x ## y
| ^
C:\ncs\v2.2.99-dev3\zephyr\include\zephyr\device.h:83:33: note: in expansion of macro '_CONCAT'
83 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
| ^~~~~~~
C:\ncs\v2.2.99-dev3\zephyr\include\zephyr\device.h:209:37: note: in expansion of macro 'DEVICE_NAME_GET'
209 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_ID(node_id))
| ^~~~~~~~~~~~~~~
C:\ncs\v2.2.99-dev3\zephyr\include\zephyr\device.h:226:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
226 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
| ^~~~~~~~~~~~~~~~~~
C:\ncs\v2.2.99-dev3\zephyr\include\zephyr\drivers\gpio.h:316:25: note: in expansion of macro 'DEVICE_DT_GET'
316 | .port = DEVICE_DT_GET(DT_GPIO_CTLR_BY_IDX(node_id, prop, idx)),\
| ^~~~~~~~~~~~~
C:\ncs\v2.2.99-dev3\zephyr\include\zephyr\drivers\gpio.h:352:9: note: in expansion of macro 'GPIO_DT_SPEC_GET_BY_IDX'
352 | GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, 0)
| ^~~~~~~~~~~~~~~~~~~~~~~
c:\ncs\workfolder\my_firstapp\src\main.c:20:40: note: in expansion of macro 'GPIO_DT_SPEC_GET'
20 | static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
| ^~~~~~~~~~~~~~~~
In file included from C:\ncs\v2.2.99-dev3\zephyr\include\zephyr\arch\arm\aarch32\arch.h:20,
from C:\ncs\v2.2.99-dev3\zephyr\include\zephyr\arch\cpu.h:19,
from C:\ncs\v2.2.99-dev3\zephyr\include\zephyr\kernel_includes.h:33:
C:\ncs\v2.2.99-dev3\zephyr\include\zephyr\devicetree.h:230:32: error: 'DT_N_ALIAS_led0_P_gpios_IDX_0_VAL_pin' undeclared here (not in a function); did you mean 'DT_N_S_gpio_reset_P_gpios_IDX_0_VAL_pin'?
230 | #define DT_ALIAS(alias) DT_CAT(DT_N_ALIAS_, alias)
| ^~~~~~~~~~~
C:\ncs\v2.2.99-dev3\zephyr\include\zephyr\devicetree.h:3912:9: note: in definition of macro 'DT_CAT7'
3912 | a1 ## a2 ## a3 ## a4 ## a5 ## a6 ## a7
| ^~
C:\ncs\v2.2.99-dev3\zephyr\include\zephyr\devicetree\gpio.h:164:9: note: in expansion of macro 'DT_PHA_BY_IDX'
164 | DT_PHA_BY_IDX(node_id, gpio_pha, idx, pin)
| ^~~~~~~~~~~~~
C:\ncs\v2.2.99-dev3\zephyr\include\zephyr\drivers\gpio.h:317:24: note: in expansion of macro 'DT_GPIO_PIN_BY_IDX'
317 | .pin = DT_GPIO_PIN_BY_IDX(node_id, prop, idx), \
| ^~~~~~~~~~~~~~~~~~
C:\ncs\v2.2.99-dev3\zephyr\include\zephyr\drivers\gpio.h:352:9: note: in expansion of macro 'GPIO_DT_SPEC_GET_BY_IDX'
352 | GPIO_DT_SPEC_GET_BY_IDX(node_id, prop, 0)
| ^~~~~~~~~~~~~~~~~~~~~~~
c:\ncs\workfolder\my_firstapp\src\main.c:20:40: note: in expansion of macro 'GPIO_DT_SPEC_GET'
20 | static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
| ^~~~~~~~~~~~~~~~
C:\ncs\v2.2.99-dev3\zephyr\include\zephyr\devicetree.h:230:25: note: in expansion of macro 'DT_CAT'
230 | #define DT_ALIAS(alias) DT_CAT(DT_N_ALIAS_, alias)
| ^~~~~~
c:\ncs\workfolder\my_firstapp\src\main.c:14:19: note: in expansion of macro 'DT_ALIAS'
14 | #define LED0_NODE DT_ALIAS(led0)
| ^~~~~~~~
c:\ncs\workfolder\my_firstapp\src\main.c:20:57: note: in expansion of macro 'LED0_NODE'
20 | static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
| ^~~~~~~~~
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: 'c:\ncs\toolchains\v2.2.99-dev3\opt\bin\cmake.EXE' --build 'c:\ncs\workfolder\my_firstapp\build'

As I have been using Visual Studio Code as the IDE, I added in the c_cpp_properperties.json in the include paths, like this:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:\\ncs\\v2.2.99-dev3\\zephyr\\include\\"
            ],
    ...

After the second attempt to build the app, it gave me same error.  I would expected that now it would be something different, but it was the same error. 

I am bit baffled now. What am I missing here?

OS: Windows

SDK: 2.2.99-dev3

IDE: Visual Studio Code

Hardware: nRF9160 Development Kid

Thanks for the help!

  • Hi,

    Are you trying any specific sample, for eg, the Lesson 2 Exercise 1? Or are you just trying the blinky sample without making any modifications to it?

    Have you tried previous nRF Connect SDK versions, say, v2.2.0 ?

    Best Regards,

    Priyanka

  • Hey, 

    After clicking around, I found the issue. I have picked the wrong build configuration. I took nrf9160dk_nrf52840 as my board in the build confguraion. However, after changing to nrf9160dk_nrf9160ns it finally resoved the symbols.

    Build configuration  nrf9160dk_nrf52840:

    Build configuration  nrf9160dk_nrf9160ns:

    Can some explain me why?

    For instance, the DT_ALIAS, which the Cmake does not find in image above, is general function for getting the node information. It should be working on every board, right?

Related