Luke Hackwell
Luke Hackwell

Reputation: 1

What am I doing wrong with my include path?

I'm new to C++, and am learning using a Mac and VSCode. I'm getting an error with my include statement:

#include "glfw3.h"

fatal error: 'glfw3.h' file not found

This is my c_cpp_properties.json:

{ "configurations": [

        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**",
                "${workspaceFolder}/include/**"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c11",
            "cppStandard": "c++98",
            "intelliSenseMode": "macos-clang-x64"
        }
    ],
    "version": 4
}

The path to glfw3.h is <root directory>/include/glfw3.h. Why can't the compiler can't find the path? When I instead put glfw2.h in the root directory, the compiler has no problem finding it.

Thanks in advance

Upvotes: 0

Views: 474

Answers (2)

aekarahan
aekarahan

Reputation: 39

.vscode/c_cpp_properties.json

"forcedInclude": [
    "C:/VulkanSDK/1.3.204.1/Include/vulkan/vulkan.h",
    "C:/glfw-3.3.6.bin.WIN64/include/GLFW/glfw3.h"
]


"includePath": [
    "${workspaceFolder}/include",
    "C:/VulkanSDK/1.3.204.1/Include/**",
    "C:/glfw-3.3.6.bin.WIN64/include/**",
    "C:/glm"
]

Upvotes: 0

Elvis Eshikena
Elvis Eshikena

Reputation: 21

Clarifications

The .vscode/c_cpp_properties.json file is only used to configure Intellisense in Visual Studio Code and not the compiler.

Compiling using the Command-line

When compiling your program using the command-line, you would need to tell the compiler where to find your include files.

g++ -I /path/to/your/include -g *.cpp -o yourProgramName

Using VSCode to compile

Since you may want to compile with visual studio code, in your .vscode/tasks.json you need to specify the -I flag.

The important lines are:

...
"args": [
    "-I",
    "${workspaceFolder}/include",
...
    ]
...

The complete .vscode/tasks.json file would look something like below:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: gcc build project",
            "command": "/path/to/your/g++",
            "args": [
                "-I",
                "${workspaceFolder}/include",
                "-g",
                "${workspaceFolder}/*.cpp",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ]
}

Then you can now run the build command by Cmd+Shift+b

Upvotes: 2

Related Questions