Linking & Compiling GLFW with MinGW

Hi, I have tried for days to get GLFW to open a window in Visual Studio Code using mingw64. I have read every forum post and nothing has worked so far. I had it easily working with VS 2022 but not with VS Code.

I get an “undefined reference to `glfwInit’” error even though libglfw3.a (64 bit version) is installed and found by the compiler. I think the error has something to do with the arguments for the compiler in my tasks.json file.

I have installed mingw64 with msys64 and can successfully compile and build 64-bit c++ programs in VS Code.

I have only done what I have mentioned here, so I don’t have any magical glfw and OpenGL files floating around anywhere, besides the default opengl32.lib file that is located in the system32 windows folder.

I am using windows 10.

File structure:


Here is my code:

#include <iostream>
#include <GLFW/glfw3.h>

int main() {
    std::cout << "Hello World!\n";
    return 0;

Here are the arguments for my tasks.json file:

"args": [
		"-lglfw3","-lopengl32","-lgdi32", "-luser32", "-lkernel32",

Terminal Output

Starting build...
C:\msys64\mingw64\bin\g++.exe -fdiagnostics-color=always -g -IC:\projects\OpenGL_Test/Dependencies/include -LC:\projects\OpenGL_Test/Dependencies/lib -lglfw3 -lopengl32 -lgdi32 -luser32 -lkernel32 C:\projects\OpenGL_Test\Application.cpp -o C:\projects\OpenGL_Test\Application.exe
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\willi\AppData\Local\Temp\ccVOsapa.o:C:\projects\OpenGL_Test/Application.cpp:5: undefined reference to `glfwInit'

collect2.exe: error: ld returned 1 exit status

Build finished with error(s).

I’m having the same issue. Were you able to solve it?

No, I’m still having the same problem. I have given up and I’m currently continuing my work in visual studio 2022 instead.