This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

VSCode Includes with custom modules? nCS

Hi Everyone,

I've started working with Zephyr, VSCode and nCS.

I'm using a sample and working on it modifiying things, but I'm not able to include extern modules, lemme explain it;

I've developed some modules that will help in my work, but when I add those to the Workspace and Try to #include it, VSCode cannot find it, also I added the path to the settings.json for the workspace with "C_Cpp.default.includePath" but nothings seems to work, I'm truly lost rn cause I need those modules to keep working...

I hope someone could light me. 

Thanks in advance to everyone,

MatiasP

  • Hi Everyone, If someone else is facing this problem, I've solved it adding 

                "browse": {
                    "path": [
                        "${workspaceFolder}/include"
                    ]
                },

    in the c_cpp_properties.json of the worspace, I was missthinking that I had to put the path in the "IncludePath" but no.

    I put the source files in src with the main.c and the header files in a folder named "include" in the root folder of the workspace.

  • Hello MatiasP,

    To include custom files in Zephyr you need to add them to your CMakeLists.txt file. You'll need to do the following:

    For header files, add this to the end of CMakeLists.txt:

    zephyr_library_include_directories(src/my_module)

    This will include the path to your include folders. After this, you should be able to include them like normally from your main.c file using:

    #include "my_custom_file.h"

    For source files, you need to add this to the end of CMakeLists.txt:

    target_sources(app PRIVATE
        src/my_module/my_custom_file.c
    )

    If you want to add more files, you can add separate them using ";"

    target_sources(app PRIVATE
        src/my_module/my_custom_file.c;
        src/my_module/my_other_custom_file.c

    I hope that answers your question. If not, please let me know.

    Best regards,

    Edvin

Related