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

Include path in VS Code using West command

Hello,

I am using VS Code 1.48.2 and building the C++ application code on nRF52840 dev board using "west" commands.

I have the following structure

project_directory/src/dummy.cpp

project_directory/src/dummy.hpp 

project_directory/src/folder/temp.hpp

I want to include "temp.hpp" in "dummy.hpp" file. I can include by doing "#include "folder/temp.hpp" but I cannot just write "#include temp.hpp"

Since I am using "west" command to build my files, I do not see a point in including paths under "c_cpp_properties.json" in vs code.

Is there a way to include path which is being detected by "west" so that I don't have to write  "#include "folder/temp.hpp" and I can build successfully just by "#include temp.hpp"?  

My CMakeLists.txt file is something like this:

target_sources(app PRIVATE
src/dummy.cpp
src/dummy.hpp
src/folder/temp.hpp
)

Parents
  • Hello,

    Have you tried adding 'zephyr_include_directories(src)' to your CMakeLists.txt. Header files shouldn't have to be added individually like source files. Also, I don't think you should have to edit "c_cpp_properties.json" if you've installed the CMake plugin in VS.

    "Kconfig for the Zephyr Project" is another plug-in you may find useful if you do everything in VS code.

  • Vidar,

    Thank you for your reply.

    Yes I have included that in my CMakelist.txt file. It is as follows:

    ############################################################

    cmake_minimum_required(VERSION 3.8)

    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(NONE)

    target_sources(app PRIVATE
    src/dummy.cpp
    src/dummy.hpp
    src/folder/temp.hpp
    )

    zephyr_library_include_directories(${CMAKE_CURRENT_SOURCE_DIR})

    ##############################################################

    But my question is not about whether I should include the header files explicitly in my CMakeList.txt or not.

    In file dummy.hpp,

    #include "folder/temp.hpp"   ->>>>>>>>>>>>>> I have to do something like this to include "temp.hpp"

    #include "temp.hpp" ->>>>>>>>>>>>>>>>>>>>I want to do something like this. In order to do this, somewhere I need to mention the path "src/folder" so that my temp.hpp file gets detected and I don't have to write "folder/temp.hpp" to include "temp.hpp" file.

  • I'm still getting familiar with the build system to be honest, but I imagine you have to specify the sub-directory in your cmake list.  E.g., zephyr_library_include_directories(src/folder/). Or have you tried it already?

Reply Children
Related