0

I am very new to OpenGL (and standalone C++) and I am trying my hardest to get anything to work.

After writing some basic code to draw a rectangle on screen, I learned I need a library loader to do basically anything (like compile shaders). So, I downloaded and installed GLFW.

However, I cannot for the life of me get GLFW to link. My setup here is pretty simple:

  • glfw3.dll is in MinGW32/bin
  • libglfw3.a and libglfwdll.a are in MinGW32/lib
  • Linker: -static-libstdc++ -static-libgcc -lglfw3 -lglfw3dll -lopengl32 -lglu32 -lglut32 (I have also tried different permutations of this, none work!)

GLUT, GLU, and OpenGL are installed in a similar manner, and all work (tested using immediate mode OpenGL).

Here is my extremely barebones program:

//GLFW_STATIC also does not work, and I do not know the difference!
#define GLFW_DLL 
#include <GLFW/glfw3.h>

int main(int argc, char** argv){
    if(!glfwInit())return 0;
    GLFWwindow* window = glfwCreateWindow(640,480,"Hello, World!",NULL,NULL);
}

And the link error:

C:\Users\...\AppData\Local\Temp\ccqpeeBm.o:Untitled1.cpp:(.text+0xf): undefined reference to `_imp__glfwInit'
C:\Users\...\AppData\Local\Temp\ccqpeeBm.o:Untitled1.cpp:(.text+0x4d): undefined reference to `_imp__glfwCreateWindow'
c:/program files (x86)/dev-cpp/mingw32/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: C:\Users\..\AppData\Local\Temp\ccqpeeBm.o: bad reloc address 0x20 in section `.eh_frame'

I have looked at other questions regarding this topic, and tried their solutions as best I could. But alas, no luck....

I am using Dev-C++ as the environment.

Any help on this topic is greatly appreciated! I have been trying for months to get OpenGL working, and this is the closest I've been!!

Fuzzyzilla
  • 356
  • 4
  • 15
  • 1
    Tried `-lglfw3dll` *instead of* `-lglfw3`? See http://www.glfw.org/docs/latest/build.html#build_link_win32 – user253751 Jan 18 '18 at 23:58
  • Thanks for that link! However, I tried the DLL instructions, and received the same error :( E: Also tried the instructions for the static version, same thing! – Fuzzyzilla Jan 19 '18 at 00:07
  • 1
    You should not be getting errors for symbols starting with `_imp__` if you are using the static version correctly; those are only for the DLL version. – user253751 Jan 19 '18 at 00:48
  • 1
    **Don't add libraries to MinGW dir!!!** Download the pre-compiled binaries. Choose static (.a) or dynamic (.dll) version. If you prefer static then tell Dev-C++ where to find the ".a" files (This is the error you get). For dynamic version the ".dll" required must be in a path that your app is able to look for, likely the same dir as your ".exe". – Ripi2 Jan 19 '18 at 01:04
  • @Ripi2 Oh, thanks for the input! The install OpenGL tutorial I saw told me to put it there! I've now fixed it, though, but receive the same error as before! – Fuzzyzilla Jan 19 '18 at 01:12
  • 1
    Review your Dev-C++ dirs for "#include" and dirs for "libglfw3.a". The link-command must use "-lglfw3" for the static version. – Ripi2 Jan 19 '18 at 01:17
  • Alright, I've fixed my entire set of libraries! Thanks for that tip :) However, this did not fix the issue! – Fuzzyzilla Jan 19 '18 at 02:27
  • @immibis When I compile with the static one instead, I get the same errors without the `_imp__` – Fuzzyzilla Jan 19 '18 at 02:32
  • The obvious question: did you put `-lglfw3` after the object files that need it? Dependencies are always satisfied left to right. Put the `-l` arguments at the end and in the right order! – Cris Luengo Jan 19 '18 at 03:30
  • @CrisLuengo I'm not sure what that means (I've never worked with a linker before), but here is my setup: `-static-libstdc++ -static-libgcc -lopengl32 -lglu32 -lgdi32 -luser32 -lkernel32 -lglfw3dll` – Fuzzyzilla Jan 19 '18 at 03:48
  • @Fuzzyzilla You have worked with a linker every time you compile a program. Since you are using an IDE your IDE should already know to put libraries after object files in the command, so you don't need to worry about that. – user253751 Jan 19 '18 at 04:30
  • Just as a side note: glfw is no extension loading library. Aren't you looking for glew or glad? Using glfw in a project that already uses glut doesn't sound likely. – BDL Jan 19 '18 at 09:11
  • @BDL The forum I saw told me to install GLFW to gain access to functions like `glShaderSource` and other GL functions. If I'm wrong, please correct me - I'm just trying as hard as I can to get this to work ;-; – Fuzzyzilla Jan 19 '18 at 19:32
  • glfw can do windowing, input handling etc and context creation/management. So in some sense: Yes. You need a library like glfw to create a context that supports this functionality. But it does not load the function pointers for these functions (unless you want to load each function manually but using `glfwGetProcAddress`. – BDL Jan 19 '18 at 20:11
  • @BDL Thank you for your information. In a last ditch effort, I downloaded glext and that seems to work (fingers crossed). Thank you all for helping me! I would submit this as an answer, but those are gone now (don't know how this is a duplicate, but I won't argue...) – Fuzzyzilla Jan 19 '18 at 20:15

0 Answers0