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

How to add custom source file ?

Hi All

I want to add some custom source files (.c) & header files (.h) to an existing project.

I tried adding it by right clicking "Project app/libapp.a" branch of the project tree.
The project compiles without error/warning, but it misses main.c file from the "Project app/libapp.a" directory.

I think I am missing some steps & thus causing this issue.

Can you please suggest me the proper method to add custom source (.c) & header (.h) files to a project?

Thank You

Shital

Parents
  • Hi Gosai, 

    To add header files and source code, create a new directory called 'include' and add all your header files. Then add your .c files in the 'src' directory. The just include the header files you want to use in the 'main.c' file. Please also see this post

    -Amanda H. 

  • Hi Amanda Hsieh

    Thanks for contributing with a solution.
    I have seen this tutorial, it is great, but there is no more detailed introduction.


    Instead, I used the below method to add custom file .h and file.c. & it worked fine.


    Open project folder C:\Nordic_SDK\ncs\nrf\samples\nrf9160\GPS
    - Project -->   src --> create new folder for custom file (ex. custom_files)
    - Add file.c , file.h and Cmaklists.txt file in custom folder (in custom_files)
    -  open main Cmakelists.txt file (C:\Nordic_SDK\ncs\nrf\samples\nrf9160\GPS\cmakelists.txt) and add below path in main custom file of your custom folder.
     1.) zephyr_library_include_directories (src/custom_folder_name)

     2.) add_subdirectory( src/custom_folder_name)


    If there is an alternative, feel free to inform me.

    Thank You

    Shital

Reply
  • Hi Amanda Hsieh

    Thanks for contributing with a solution.
    I have seen this tutorial, it is great, but there is no more detailed introduction.


    Instead, I used the below method to add custom file .h and file.c. & it worked fine.


    Open project folder C:\Nordic_SDK\ncs\nrf\samples\nrf9160\GPS
    - Project -->   src --> create new folder for custom file (ex. custom_files)
    - Add file.c , file.h and Cmaklists.txt file in custom folder (in custom_files)
    -  open main Cmakelists.txt file (C:\Nordic_SDK\ncs\nrf\samples\nrf9160\GPS\cmakelists.txt) and add below path in main custom file of your custom folder.
     1.) zephyr_library_include_directories (src/custom_folder_name)

     2.) add_subdirectory( src/custom_folder_name)


    If there is an alternative, feel free to inform me.

    Thank You

    Shital

Children
No Data
Related