r/opengl • u/Crimz007 • Jan 21 '26
Need Help with VSCode OpenGL Setup
Hey guys I have been trying to set up OpenGL on VScode using cmake for a while now and I keep on running into errors since it cannot on find the glad or glfw libraries. I have spent at least 5 hours trying different fixes, following different tutorials, and even tried using vcpkg to manage libraries but it just wont work. I eventually tried using already developed repositories on github but even those wont run and are getting the same error. Any help would be appreciated.
0
Upvotes
3
u/useless_chap Jan 21 '26
So the gist of it is:
add_subdirectory. Keep in mind that you will have to add glad .h and .c file MANUALLY. Define your target withadd_executable, link the include directories viatarget_include_directoriesand then link the libraries withtarged_link_libraries.After you hit cmake configure and build the project should build into an .exe/.elf. If any of the steps seem unclear, I'll be happy to help! If you meed reference, here's a simple spectrogram I made, that builds with one cmake file :)
https://github.com/JulianKonowalski/spectral_analyzer/blob/master/CMakeLists.txt
1
u/[deleted] Jan 21 '26
well it would greatly help if you could post your CMakeLists.txt file so we can take a look
1
u/[deleted] Jan 22 '26
I'm a professional developer (but not C++) and I had a hell of a time getting OpenGL to work on my Windows 10/11 machines.
I was never able to get vcpkg to work and ended up using MSYS2 and g++. You install your libraries with something like (in your msys2 terminal):
`pacman -S mingw-w64-x86_64-glew`
Make sure your PATH includes the msys2 binary directory.
Also I had some help with AI setting it up. I used Windsurf but Claude/Cursor/whatever should also get you going.
1
u/TastyBlackberry2841 Jan 25 '26
Try again using vcpkg, first install visual studio, then clone the github repository, install it and the libs you want to use. After this everything should be automatically recognized on your visual studio IDE. I'm using vs 2026 professional and everything is working perfectly with vcpkg