Skip to content
Advertisement

Add OpenGL to Linux Vscode

I followed this tutorial successfully. But it doesn’t explain how to configure on vscode. Glad is in this folder /usr/include and I did use sudo in the terminal to compile and generate a.out. How do I do that in vscode? I have this error output when I try to build task:

terminal

Starting build...
/usr/bin/g++ -fdiagnostics-color=always -g /home/raijin/Documents/Code/C++/OpenGL/*.cpp -I/home/raijin/Documents/Code/C++/OpenGL/ -o /home/raijin/Documents/Code/C++/OpenGL/main
/home/raijin/Documents/Code/C++/OpenGL/main.cpp:3:10: fatal error: /usr/include/glad/glad.h: Permission denied
    3 | #include <glad/glad.h>

My tasks is configured like that:

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${workspaceFolder}/*.cpp",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
                
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "compiler: /usr/bin/g++"
        }
    ]
}

How do I configure OpenGL vscode?

Advertisement

Answer

If anyone has the same problem I solved it adding these args in tasks.json

"${workspaceFolder}/*.c",
"-lGL",
"-lglfw",
"-ldl"

And the folder glad in /usr/include for some reason had a gray x on the folder icon and it couldn’t be accessed without sudo command. I deleted and made a glad empty folder and copied glad.h inside it. After that the code worked as expected in vscode.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement