getting error while compiling nordic bluetooth le advertising example 1

so basically i am having this problem in compiling this program .. basically i am running this example of nordic exercise 1 but i am not able to compile it i am attaching the code 

#include <zephyr/kernel.h>

#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/gap.h>


static const struct bt_data ad[] = {
    /* STEP 4.1.2 - Set the advertising flags */
    BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_NO_BREDR),
    /* STEP 4.1.3 - Set the advertising packet data  */
    BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),

};
static unsigned char url_data[] ={0x17,'/','/','a','c','a','d','e','m','y','.',
                                 'n','o','r','d','i','c','s','e','m','i','.',
                                 'c','o','m'};
static const struct bt_data sd[] = {
        /* 4.2.3 Include the URL data in the scan response packet*/
        BT_DATA(BT_DATA_URI, url_data,sizeof(url_data)),

};


int main(void)
{
    err = bt_enable(NULL);

if (err) {
    LOG_ERR("Bluetooth init failed (err %d)\n", err);
    return;
}

LOG_INF("Bluetooth initialized\n");

err = bt_le_adv_start(BT_LE_ADV_NCONN, ad, ARRAY_SIZE(ad),sd, ARRAY_SIZE(sd));

if (err) {
        LOG_ERR("Advertising failed to start (err %d)\n", err);
        return;
    }


}
and i am also adding the error log 
Building my_ble_bas
C:\Windows\system32\cmd.exe /d /s /c "west build --build-dir c:/nordic/myapp/my_ble_bas/build c:/nordic/myapp/my_ble_bas"

[1/120] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/string/strncasecmp.c.obj
[2/120] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdlib/bsearch.c.obj
[3/120] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/string/strerror.c.obj
[4/120] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/string/strspn.c.obj
[5/120] Building C object CMakeFiles/app.dir/src/main.c.obj
FAILED: CMakeFiles/app.dir/src/main.c.obj
C:\ncs\toolchains\31f4403e35\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.4.0/nrf/drivers/mpsl/clock_control -IC:/ncs/v2.4.0/zephyr/include -Izephyr/include/generated -IC:/ncs/v2.4.0/zephyr/soc/arm/nordic_nrf/nrf52 -IC:/ncs/v2.4.0/zephyr/soc/arm/nordic_nrf/common/. -IC:/ncs/v2.4.0/zephyr/subsys/bluetooth -IC:/ncs/v2.4.0/nrf/include -IC:/ncs/v2.4.0/nrf/lib/multithreading_lock/. -IC:/ncs/v2.4.0/nrf/subsys/bluetooth/controller/. -IC:/ncs/v2.4.0/nrf/tests/include -IC:/ncs/v2.4.0/modules/hal/cmsis/CMSIS/Core/Include -IC:/ncs/v2.4.0/modules/hal/nordic/nrfx -IC:/ncs/v2.4.0/modules/hal/nordic/nrfx/drivers/include -IC:/ncs/v2.4.0/modules/hal/nordic/nrfx/mdk -IC:/ncs/v2.4.0/zephyr/modules/hal_nordic/nrfx/. -IC:/ncs/v2.4.0/modules/debug/segger/SEGGER -IC:/ncs/v2.4.0/modules/debug/segger/Config -IC:/ncs/v2.4.0/zephyr/modules/segger/. -IC:/ncs/v2.4.0/nrfxlib/mpsl/include -IC:/ncs/v2.4.0/nrfxlib/mpsl/include/protocol -IC:/ncs/v2.4.0/nrfxlib/softdevice_controller/include -isystem C:/ncs/v2.4.0/zephyr/lib/libc/minimal/include -isystem c:/ncs/toolchains/31f4403e35/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/include -isystem c:/ncs/toolchains/31f4403e35/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/include-fixed -isystem C:/ncs/v2.4.0/nrfxlib/crypto/nrf_cc310_platform/include -fno-strict-aliasing -Os -imacros C:/nordic/myapp/my_ble_bas/build/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m4 -mthumb -mabi=aapcs --sysroot=C:/ncs/toolchains/31f4403e35/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi -imacros C:/ncs/v2.4.0/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -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:/nordic/myapp/my_ble_bas=CMAKE_SOURCE_DIR -fmacro-prefix-map=C:/ncs/v2.4.0/zephyr=ZEPHYR_BASE -fmacro-prefix-map=C:/ncs/v2.4.0=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:\nordic\myapp\my_ble_bas\src\main.c:3:
c:\nordic\myapp\my_ble_bas\src\main.c:11:53: error: 'DEVICE_NAME_LEN' undeclared here (not in a function)
11 | BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
| ^~~~~~~~~~~~~~~
C:\ncs\v2.4.0\zephyr\include\zephyr\bluetooth\bluetooth.h:447:30: note: in definition of macro 'BT_DATA'
447 | .data_len = (_data_len), \
| ^~~~~~~~~
c:\nordic\myapp\my_ble_bas\src\main.c:11:40: error: 'DEVICE_NAME' undeclared here (not in a function)
11 | BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
| ^~~~~~~~~~~
C:\ncs\v2.4.0\zephyr\include\zephyr\bluetooth\bluetooth.h:448:43: note: in definition of macro 'BT_DATA'
448 | .data = (const uint8_t *)(_data), \
| ^~~~~
../src/main.c: In function 'main':
c:\nordic\myapp\my_ble_bas\src\main.c:26:9: error: 'err' undeclared (first use in this function)
26 | err = bt_enable(NULL);
| ^~~
c:\nordic\myapp\my_ble_bas\src\main.c:26:9: note: each undeclared identifier is reported only once for each function it appears in
c:\nordic\myapp\my_ble_bas\src\main.c:29:9: warning: implicit declaration of function 'LOG_ERR' [-Wimplicit-function-declaration]
29 | LOG_ERR("Bluetooth init failed (err %d)\n", err);
| ^~~~~~~
c:\nordic\myapp\my_ble_bas\src\main.c:30:9: warning: 'return' with no value, in function returning non-void [-Wreturn-type]
30 | return;
| ^~~~~~
c:\nordic\myapp\my_ble_bas\src\main.c:24:5: note: declared here
24 | int main(void)
| ^~~~
c:\nordic\myapp\my_ble_bas\src\main.c:33:1: warning: implicit declaration of function 'LOG_INF' [-Wimplicit-function-declaration]
33 | LOG_INF("Bluetooth initialized\n");
| ^~~~~~~
c:\nordic\myapp\my_ble_bas\src\main.c:39:17: warning: 'return' with no value, in function returning non-void [-Wreturn-type]
39 | return;
| ^~~~~~
c:\nordic\myapp\my_ble_bas\src\main.c:24:5: note: declared here
24 | int main(void)
| ^~~~
[6/120] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdout/stdout_console.c.obj
[7/120] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/string/strstr.c.obj
[8/120] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/math/sqrtf.c.obj
[9/120] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/string/string.c.obj
[10/120] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdout/sprintf.c.obj
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: 'C:\ncs\toolchains\31f4403e35\opt\bin\cmake.EXE' --build 'c:\nordic\myapp\my_ble_bas\build'
Parents
  • Hey Roy,

    There is a lot going on here. First of all, you don't have DEVICE_NAME or DEVICE_NAME_LEN defined. An example of that would be:

    #define DEVICE_NAME CONFIG_BT_DEVICE_NAME
    #define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)

    However, you will also need to make sure that CONFIG_BT_DEVICE_NAME is set in your proj.conf file as well. So, in proj.conf you can have something like:

    CONFIG_BT_DEVICE_NAME="Test"

    Secondly, the main signature (i.e. int main(void)) has a return type of int. The main should always return 0 in Zephyr, so change return; to return 0; in the main function. Thirdly, you don't have err defined. So add, int err; to the top of main, something like this:

    int main(void)
    {
        int err;
        
        // code here
        
        return 0;
    }

    Also, if you see error messages like, "warning: implicit declaration of function", then that means your using a function call that does not exist. In this example, your using LOG_INF, but it's never defined, so the compiler doesn't know where to find it or what to do with it.

    I would suggest going through the exercise again and taking note of these points.

Reply
  • Hey Roy,

    There is a lot going on here. First of all, you don't have DEVICE_NAME or DEVICE_NAME_LEN defined. An example of that would be:

    #define DEVICE_NAME CONFIG_BT_DEVICE_NAME
    #define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)

    However, you will also need to make sure that CONFIG_BT_DEVICE_NAME is set in your proj.conf file as well. So, in proj.conf you can have something like:

    CONFIG_BT_DEVICE_NAME="Test"

    Secondly, the main signature (i.e. int main(void)) has a return type of int. The main should always return 0 in Zephyr, so change return; to return 0; in the main function. Thirdly, you don't have err defined. So add, int err; to the top of main, something like this:

    int main(void)
    {
        int err;
        
        // code here
        
        return 0;
    }

    Also, if you see error messages like, "warning: implicit declaration of function", then that means your using a function call that does not exist. In this example, your using LOG_INF, but it's never defined, so the compiler doesn't know where to find it or what to do with it.

    I would suggest going through the exercise again and taking note of these points.

Children
No Data
Related