1

I am using GLFW for a c++ project. I downloaded glfw3 using homebrew and have "/opt/homebrew/include" in the "includePath" field of the c++ configurations json file for vs code. Following the solution provided by this post (MacOS M1 -> fatal error: 'GLFW/glfw3.h' file not found), I also added the two paths to the .zshrc file, using terminal commands:

echo -n 'export CPATH=/opt/homebrew/include' >> ~/.zshrc (I also added export CPPPATH=...)

and

echo -n 'export LIBRARY_PATH=/opt/homebrew/lib' >> ~/.zshrc

, respectively. However, at compilation it still says that "GLFW/glfw3.h" is not found, even though the statement completion feature correctly identified both GLFW folder and glfw3.h file in the member lists. Thanks for your help!

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1",
                "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include",
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include",
                "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include",
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks",
                "/opt/homebrew/include",
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "macFrameworkPath": [],
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "macos-clang-arm"
        }
    ],
    "version": 4
}

tasks.json

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: clang++ build active file",
            "command": "/usr/bin/clang++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

launch.json

{
    "version": "0.2.0",
    "configurations": [
        
        
        {
            "name": "clang++ - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb",
            "preLaunchTask": "C/C++: clang++ build active file"
        }
    ]
}
drescherjm
  • 10,365
  • 5
  • 44
  • 64
Xi Liu
  • 559
  • 9
  • 18
  • How are you building? Did you verify that `/opt/homebrew/include/GLFW/glfw3.h` exists? – drescherjm Jun 02 '21 at 21:58
  • You mentioned VSCode. Did you modify `tasks.json` and `c_cpp_properties.json`? Or are you using code runner? Or the CMake or Makefile addon? – drescherjm Jun 02 '21 at 22:00
  • Yes. Using this path Finder correctly located glfw3.h – Xi Liu Jun 02 '21 at 22:01
  • I am using clang – Xi Liu Jun 02 '21 at 22:08
  • If you are using VSCode and building from inside VSCode did you add the path in your `tasks.json` and `c_cpp_properties.json` files? The instructions these files is here: [https://code.visualstudio.com/docs/cpp/config-clang-mac](https://code.visualstudio.com/docs/cpp/config-clang-mac) – drescherjm Jun 02 '21 at 22:10
  • You did not add the path in the tasks.json. Related: [https://stackoverflow.com/questions/52910102/vscode-c-task-json-include-path-and-libraries](https://stackoverflow.com/questions/52910102/vscode-c-task-json-include-path-and-libraries) – drescherjm Jun 02 '21 at 22:11
  • Got it but where should I put it? Placing it after "${file}" or "${fileDirname}/${fileBasenameNoExtension}" in "args" still does not solve the issue. – Xi Liu Jun 02 '21 at 22:19
  • Adding "IC:" before the path fixes the issue! – Xi Liu Jun 02 '21 at 22:22
  • Thanks man! You are so helpful. But what does the keyword "IC mean? – Xi Liu Jun 02 '21 at 22:26
  • It should be `-I` then then the folder – drescherjm Jun 03 '21 at 00:58

0 Answers0