Home > Enterprise >  clang library not found even when providing library path
clang library not found even when providing library path

Time:05-08

I was trying to create a new OpenGL project with glfw and glad using vs code on an m1 Mac, and setup the files such that I have the include folder and lib folder which contains the necessary headers and library (libglfw3.a) files and the src folder that contains the glad.c and main.cpp, all in my workspace folder.

I have modified the tasks.json file like such:

{
"version": "2.0.0",
"tasks": [
    {
        "type": "cppbuild",
        "label": "C/C  : clang   build active file",
        "command": "/usr/bin/clang  ",
        "args": [
            "-fdiagnostics-color=always",
            "-g",
            "-std=c  17",
            "-I${workspaceFolder}/include",
            "-L${workspaceFolder}/lib",
            "${workspaceFolder}/src/*.cpp",
            "${workspaceFolder}/src/glad.c",
            "-llibglfw3",
            "-o",
            "${workspaceFolder}/game"
        ],
        "options": {
            "cwd": "${fileDirname}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "detail": "compiler: /usr/bin/clang  "
    }
]

}

However, I get the following error:

ld: library not found for -llibglfw3 
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I thought that I had properly included the path to the glfw library, but it says that it could not find the library. What am I doing wrong?

As a side-note, I have followed this tutorial to setup the program, but this post assumes that you have a windows machine, so I had downloaded/changed some things to my knowledge of what would work with the m1 mac.

CodePudding user response:

Normally when you give libraries to link with the -l flag, you omit the lib prefix. For example: "-lglfw3" links the file "libglfw3.a". It looks like you should change your -llibglfw3 option.

  • Related