This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

About file path in the header file

Hi 
I am the user of zephyr and nrf connect SDK in ubuntu 20.04.
one question about file path in the header file.
for instance, the demonstration "nrf/samples/zigbee/light_switch ".

#include <zboss_api.h>
#include <zboss_api_addons.h>
#include <zigbee/zigbee_app_utils.h>...

would you please advise how i can find the include path?
is there any guide or manual for reference?
  • Hello,

    The NCS (nRF Connect SDK) is based on CMake, so the include folders are basically set up to include the entire SDK, so all you need to do to include a header file from the SDK is to use #include.

    If you want to know where this folder is located, you can just search for it in the NCS sdk. 

    If you want to create a new header file, and place it in a folder, you need your project to include this folder, like it is done in the other CMakeLists.txt.

    I can use the peripheral_uart example found in ncs\nrf\samples\bluetooth\peripheral_uart as an example.

    First, create a folder next to the src folder called custom_files:

    inside your custom_files folder, create two folders, one called "src" and one called "include". 

    To add this include folder to the list of folders that the compiler will look for header files, open the CMakeLists.txt, and add:

    zephyr_library_include_directories(custom_files/include)
    right after
    zephyr_library_include_directories(.)
    Then create two files:
    test_file.h in your include folder, and test_file.c in your src folder.
    After that, go back to the CMakeLists.txt, and locate the target_sources() call.
    Add your custom .c file:
    # NORDIC SDK APP START
    target_sources(app PRIVATE
      src/main.c;
      custom_files/src/test_file.c
    )
    Now you can include the header file from your main.c file using "#include "test_file.h", and if you declare a function in that file, define it in the .c file, you can use it from main.c.
    Attaching my test files here:
    #include <stdio.h>
    #include <logging/log.h>
    
    
    #define LOG_MODULE_NAME test_file
    LOG_MODULE_REGISTER(LOG_MODULE_NAME);
    
    void test_function(void)
    {
    	//do nothing
    	printf("test_function\r\n");
    }
    using the test_function() from main will print "test_function" over UART.
    Best regards,
    Edvin
  • Dear Edvin

    This is very useful for my research.
    Thank you so much for responding to my question.

Related