How to add header file (.h) and lib file (.lib) into custom project?

Hi all,

I am using NRF5340 with nRF Connect SDK v1.9.1. And I want to add my own .h and .lib(GCC) file into my project. 

Please tell me how to do.

Thanks a lot!

  • It is quite a simple process to add libraries into your CMakeLists.txt file.

    There is a demo sample for this that you can try to understand that resides in ncs\vx.x.x\zephyr\samples\application_development\external_lib

    If you open CMakeLists.txt file you can see how library is added to your project

    # Create a wrapper CMake library that our app can link with
    add_library(mylib_lib STATIC IMPORTED GLOBAL)
    add_dependencies(
      mylib_lib
      mylib_project
      )
    
    target_link_libraries(app PUBLIC mylib_lib)

    in terms of adding a header file, you just need to add the path of the header first in the same CMakeLists.txt file and you can include the header in the source file normally after that.

Related