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

How to add a custom header and c file into a project.

Hi,

I have a ncs project which currently has only the main.c file.

I want to create a header file and the c file to be included in the main. 

What's the recommended way to do this.

I tried creating them manually in the src folder - failed.

I tried creating separate include folder for the header files - failed.

TIA.

Parents
  • Hello!

    For one you need to include the c-file in your CMakeLists.txt file, by adding: "target_sources(app PRIVATE src/[filename])", and then re-run CMake by either using the 'Project' drop-down menu, or reopening the project. Then the files should be visible in SES, and be a part of your project.

    I recommend taking a look at this tutorial that explains all of this in further detail. Part 2 may be particularly interesting.

    Let me know if this didn't help, or if there is anything else!

    Best regards,

    Håkon

Reply
  • Hello!

    For one you need to include the c-file in your CMakeLists.txt file, by adding: "target_sources(app PRIVATE src/[filename])", and then re-run CMake by either using the 'Project' drop-down menu, or reopening the project. Then the files should be visible in SES, and be a part of your project.

    I recommend taking a look at this tutorial that explains all of this in further detail. Part 2 may be particularly interesting.

    Let me know if this didn't help, or if there is anything else!

    Best regards,

    Håkon

Children
Related