trouble with including header files and with Task.JSON

76 Views Asked by At

So I am trying to test out my program and whenever I do I get errors like "fatal error: board.h: No such file or directory". this has led me to look up some stuff on how to compile a c++ file in VS Code. I am honestly am very new to this and am having trouble understanding what is going wrong.

here is my file structure:

chessgame|

---------------- build-|

----------------- include-| - board.h, rules.h, interface.h
    
------------------src-| - board.cpp, rules.cpp, interface.cpp, chessgame.cpp

my interface.h has a #include "board.h" because some of the functions need a reference to a board instance.

my rules.h has a #include "board.h" because some of the functions need a reference to a board instance.

my board.cpp file has #include "board.h" and #include "rules.h"

my chessgame.cpp has #include "board.h" and #include "rules.h" and #include "interface.h"

my interface.cpp has #include "interface.h"

my rules.cpp has #include "rules.h"

now when I try to debug I get errors like:

/home/user/project_C++/chessgame/src/chessgame.cpp:2:10: fatal error: interface.h: No such file or directory
    2 | #include "interface.h"

here is my c_cpp_properties.json file:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/src",
                "${workspaceFolder}/include",
                "${workspaceFolder}"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c17",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],
    "version": 4
}

here is tasks.json file:

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++-9 build active file",
            "command": "/usr/bin/g++-9",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${workspaceFolder}/src/chessgame.cpp",
                "${workspaceFolder}/src/board.cpp",
                "${workspaceFolder}/src/interface.cpp",
                "${workspaceFolder}/src/rules.cpp",
                "${workspaceFolder}/include/interface.h",
                "${workspaceFolder}/include/board.h",
                "${workspaceFolder}/include/rules.h",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

does anyone know what could be causing these errors.

I have tried to update my task.json file and c_cpp_properties.json multiple times but I still get the same errors.

0

There are 0 best solutions below