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

Why is ble_cus.c not a header file

In this tutorial

github.com/.../custom_ble_service_example

There are two additional files added to the template project

ble_cus.c
ble_cus.h

I understand that ble_cus.h must be included as a header in both ble_cus.c and main.c

However, my code doesn't compile unless I also #include ble_cus.c in main.c like this

// main.c
#inlcude ble_cus.c
#inlcude ble_cus.h

My question is, why isn't ble_cus.c defined as a header file i.e. with a .h extension? What is the purpose of making it a .c file? Am I missing something?

Additionally, if ble_cus.h is included as a header in ble_cus.c then don't I only have to #include ble_cus.c in main.c?

// main.c
#inlcude ble_cus.c
//#inlcude ble_cus.h

Thanks

Parents
  • Hi,

    You should not include source files the same way you include header files. The header files provide the declaration of variables and functions to your main application, while the source code should contain implementation of functions. Source files are included in the project and is compiled separately into object files. The object files are then linked into the complete application, together with main.

    In Keil, you add source files by right clicking the group you want to the file to, for instance nRF_BLE_Services, and click "Add Existing Files to Group '...'".

    Best regards,

    Jørgen

Reply
  • Hi,

    You should not include source files the same way you include header files. The header files provide the declaration of variables and functions to your main application, while the source code should contain implementation of functions. Source files are included in the project and is compiled separately into object files. The object files are then linked into the complete application, together with main.

    In Keil, you add source files by right clicking the group you want to the file to, for instance nRF_BLE_Services, and click "Add Existing Files to Group '...'".

    Best regards,

    Jørgen

Children
No Data
Related