Hello, I believe g++ is very particular about the order in which you include your source files.
I'll explain my steps:
1. I downloaded glew 2.1.0 and built libglew32.a (with msys2).
1. a. While trying to run make, I was previously running into this error
https://stackoverflow.com/questions/40392221/undefined-reference-to-fprintf-glewinfo-c-building-glew-makefile-with-msys but the answer to that question fixed it (prevent glew from preventing linkage with stdio).
1. b. (Since it sounds like you already built the .a file, you probably don't need to worry about this)
2. Afterwards, with your same src code, I tried to build it with the following command line:
g++ -Wall -I C:/libraries/glew-2.1.0/include -L C:/libraries/glew-2.1.0/lib -lglew32 main.cpp -o out.exe |
And got :
Temp\ccdZVbMB.o:main.cpp:(.text+0x10): undefined reference to `__imp_glewInit'
collect2.exe: error: ld returned 1 exit status |
3. After this, I changed the ordering of the command-line options.
g++ -Wall
main.cpp -I C:/libraries/glew-2.1.0/include -L C:/libraries/glew-2.1.0/lib -lglew32 -o out.exe
And it compiled.
I moved main.cpp before any linker dependencies. I believe this is what matters, because g++ only looks for existing dependencies when looking through the libraries linked (that's what I believe to be true, anyway).
According to your makefile, it looks like your command-line is being formed in such as a way that the *.cpp files are being put a the END of the command line. Move the *.cpp part to BEFORE you include your linker options.
Personally, I'd prefer using GLAD over GLEW because it only requires 1 header file and implementation file, which is auto-generated by the tool at
https://github.com/Dav1dde/glad
I personally dislike GLEW's site because it's one of those sites that conflates MS Windows and Visual Studio.
Edit: One caveat, even when specifying DGLEW_STATIC, I still needed to put glew32.dll inside the same folder as out.exe. I don't know why. But whatever. It runs. Note that glewInit requires a proper window context to exist to return OK.