Issues Building OpenGL Project with GLFW and GLEW on Windows using MSYS2/MinGW

Hello,

I’m currently facing some challenges while trying to build a C++ project that uses OpenGL, GLFW, and GLEW on a Windows machine. I am working with MSYS2/MinGW as the build environment and VSCode as a text editor (without relying on IDEs). My goal is to manually configure the environment, set up the necessary variables, and automate the build process using a custom script (run.sh). Eventually, I plan to run the project within a Docker container to ensure a consistent and portable environment.

Here’s a summary of the issues I’ve encountered so far:

glfw3.h Not Found:
The most significant issue I am facing is that the compiler cannot locate glfw3.h, even though I’ve explicitly set the include path in my build script (run.sh). Despite verifying that the header file exists in ./Dependencies/GLFW/include/GLFW/glfw3.h, the compiler returns a “No such file or directory” error.Manual Setup:

I prefer not to depend on IDEs, so I’m setting up everything manually: environment variables, include paths, and libraries. The run.sh script is designed to automate the build process, but it is still not functioning as expected. I’ve tried to set up the environment in MSYS2, manually defining paths for GLFW and GLEW.

VSCode Setup:
While I am using VSCode as a text editor, it’s not being used as an IDE. I only use it for editing the source code, and I’m avoiding relying on any built-in build systems that might be provided by the editor.

My next steps are to resolve these issues and get the project building successfully. Once that’s done, I plan to try running the project in Docker to ensure a portable and consistent environment, making the setup reproducible across different machines.

I would greatly appreciate any assistance or advice on resolving the “file not found” issue for glfw3.h and making the build process work smoothly with the manual setup and automation I’ve described.

Here is the link to my GitHub project for reference:

Thank you in advance for your help!

From the looks your problem might be that your source code specifies:

#include <GLFW/glfw3.h>

But you are setting the include directory to:

"./Dependencies/include/GLFW"

You should instead set it to:

"./Dependencies/include/"

So that it can find GFLW/glfw3.h

Trying to do everything yourself via the command line and using MSYS2/MINGW is at the higher end of the difficulty level. I would not recommend doing this unless you have a high level of expertise.

If you continue to have issues I would investigate using: GitHub - enkisoftware/GLFW-CMake-starter: Use CMake to create a project with GLFW - Multi-platform Windows, Linux and MacOS.

Thanks for reply!!

I made the change you mentioned, and it worked! However, I’m encountering another error now. Here’s the log:

When I run ./run.sh in Git Bash:

$ ./run.sh
collect2.exe: error: ld returned 5 exit status
Compilation failed

This time, it actually creates an executable, but when I try to run it through PowerShell, this happens:

.\build\OpenGL_Test.exe
The program 'OpenGL_Test.exe' failed to execute: The specified executable is not a valid application for this OS platform.
At line:1 char:1
+ .\build\OpenGL_Test.exe
+ ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
    + FullyQualifiedErrorId : NativeCommandFailed

It’s worth mentioning that I understand the difficulty involved in using just command-line tools with MSYS2/MinGW. I intend to keep fighting to learn this way because, as silly as it may seem, it helps me a lot to continue understanding how things work! If you have any further tips, I’d appreciate it. For now, I’ll try to figure out what might be causing these errors. If you have any guesses, I would be grateful if you could share them.

I recommend learning by starting with something simple and working from there.

On Windows I recommend the Visual Studio Community edition tool chain, with CMake and the above CMake starter.

If you want to continue with your approach perhaps this stackoverflow issue will help.

Thank you for the reply, I really appreciate your help and I will continue with my approach. I will update you if I manage to solve the problem.