Recently I have been interested in graphic programming. I read a few tutorials and have found opengl is where I should start.
So I start setting up the opengl dev environment, but its not easy since I am using window (and vscode)...
Preparation
- GLFW
- Precompiled
- https://www.glfw.org/download.html
- GLAD
- Vscode C++
- https://code.visualstudio.com/docs/cpp/config-mingw#_prerequisites
- Compiler: MinGW-w64 via MSYS2
pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain
- C/C++ Extension
- https://medium.com/@vivekjha92/setup-opengl-with-vs-code-82852c653c43
- Restart Vscode if needed
Setting up
glfw lib
https://www.glfw.org/docs/latest/build_guide.html#build_link_mingw
- Static (I am using this)
- libglfw3.a
- For DLL version
- add
#define GLFW_DLL
in the first line of code - use the libglfw3dll.a one in lib
- add
vscode task.json arg
Make sure the flag order is correct
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"src/glad.c",
"-I./include",
"-L./lib",
"-lglfw3",
"-lgdi32",
]
file structure
Now I think I can start learning opengl :)
Here some problems I encountered when figuring how to setup the environment
lglfw3 not found
- make sure the file structure is correct
"undefined reference to `glfwTerminate'"
- linker problem
- so make sure the compiler flag and order are correct
std::cout not working after adding glfw related functions
- probably linker problem also
- check the compiler flag and file structure are all correct
Ref
https://stackoverflow.com/questions/22623087/undefined-reference-errors-when-linking-glfw-on-mingw
Top comments (0)