I've had this sort of issue before (and have even asked on this forum for solutions) but prior fixes don't seem to be working for me this time.
In short, I am writing a program that goes like this:
#include <GLFW\glfw3.h>
int main()
{
if (!glfwInit()) return 1;
glfwTerminate();
return 0;
}
I compile with more-or-less this instruction (more on that in a bit):
gcc -x c++ -Iinclude -owindow.exe window.cpp -lglfw3 -Llib
My file structure is as follows:
OpenGL Test 2-Window (root)
--include (directory)
----GLFW (directory)
------**glfw3.h** (glfw header)
------**glfw3native.h** (glfw header)
--lib (directory)
----**libglfw3.a** (static library for MinGW-w64)
--**window.cpp** (contains the code from above)
I can't see any problems with this setup (I am naïve after all), yet despite all my rage the compiler continues to return the following error:
C:\privatepath\cc6uFxnu.o:window.cpp:(.text+0xc): undefined reference to `glfwInit'
C:\privatepath\cc6uFxnu.o:window.cpp:(.text+0x21): undefined reference to `glfwTerminate'
collect2.exe: error: ld returned 1 exit status
I have tried:
-Rearranging the arguments in the compile instructions
-Importing the static lib file as code instead of linking it
-Linking gdi32 along with glfw
-Reorganizing the glfw files
and none of those did anything helpful.
So my question is twofold: what's going on here, and how do I fix it? Thanks for the help.
EDIT (1/4/25): Forgot to mention--I'm running MinGW on a Windows 10 machine.
EDIT (1/5/25): Neither of the questions listed as "duplicates" offer solutions (though they are similar situations). The first question's solution just didn't work (already tried that before writing this post), and the second one is irrelevant given that it discusses dynamic linking rather than static linking (also I deleted all dynamic link files from my workspace, so "confusing the linker" with the wrong files is certainly not the issue).
Answering my own question here: had to compile GLFW myself, then compile using gcc instead of gcc -x c++, THEN add -lgdi32 to the compile instruction. This has solved the issue for me on on two separate machines. Thanks to @drescherjm, @Alan Birtles, and @Brecht Sanders for their help resolving the issue.