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

How do I include a library in a new project?

Probably a silly question, but I am new to Nordic Semiconductor and can't figure this out. I am trying to make a new project based on the Template example for nrf51422_xxac_s100 and am getting an error when I try to include the "ble_nus.h" library that is used in other example projects. The nRF_BLE software pack is included in the Template project (where I found the ble_nus in other projects). If I try adding "#include "ble_nus.h" in main.c, it gives me: "fatal error: 'ble_nus.h' file not found". I am using Keil uVersion 5. Thanks in advance!

Parents
  • A library generally contains a library_name.h file and a library_name.c file. If using the .zip style architecture, you need to include both files in your project. When you have included the files in your project, you can use the library by calling its various functions.

    To include the library_name.h file, start with adding the path to the library_name.h file as Øyvind has described in his answer. Additionally, type the following at the top of your main.c file or whatever file you want to call call the library from:

    #include library_name.h
    

    If the library also contains a .c file, then you must include that also with the following:

    • Open "Manage Project Items" by clicking (1)
    • Click (2) and add the group "nRF_Libraries" if it not already exists
    • Select "nRF_Libraries" and click (3) to add library_name.c file to the "nRF_Libraries" group

    image description

    Now you should be able to use the library and call its various functions.

    If you compile and get errors that files are missing or can not be found, you should add those files (.h and perhaps also .c files) into your project in the same way as described here.

Reply
  • A library generally contains a library_name.h file and a library_name.c file. If using the .zip style architecture, you need to include both files in your project. When you have included the files in your project, you can use the library by calling its various functions.

    To include the library_name.h file, start with adding the path to the library_name.h file as Øyvind has described in his answer. Additionally, type the following at the top of your main.c file or whatever file you want to call call the library from:

    #include library_name.h
    

    If the library also contains a .c file, then you must include that also with the following:

    • Open "Manage Project Items" by clicking (1)
    • Click (2) and add the group "nRF_Libraries" if it not already exists
    • Select "nRF_Libraries" and click (3) to add library_name.c file to the "nRF_Libraries" group

    image description

    Now you should be able to use the library and call its various functions.

    If you compile and get errors that files are missing or can not be found, you should add those files (.h and perhaps also .c files) into your project in the same way as described here.

Children
No Data
Related