Reputation: 1386
I'm trying to learn OpenGL with GLFW, but I'm having some problems.
This is my main.cpp:
#include <GL/glfw.h>
int main()
{
glfwInit();
glfwSleep( 1.0 );
glfwTerminate();
}
This is my project's folder structure:
Project
+- glfw.dll
+- main.cpp
This is where I extracted the GLFW files:
MinGW
+- include
| +- GL
| +- glfw.h
+- lib
+- libglfw.a
+- libglfwdll.a
And this is how I try to build the program:
g++ main.cpp -o main.exe -lglfwdll
And these are the errors I'm getting:
C:\Users\Dark\AppData\Local\Temp\cc0ZgTVp.o:main.cpp:(.text+0xf): undefined reference to `_glfwInit'
C:\Users\Dark\AppData\Local\Temp\cc0ZgTVp.o:main.cpp:(.text+0x25): undefined reference to `_glfwSleep'
C:\Users\Dark\AppData\Local\Temp\cc0ZgTVp.o:main.cpp:(.text+0x2a): undefined reference to `_glfwTerminate'
collect2.exe: error: ld returned 1 exit status
Am I missing something?
Upvotes: 10
Views: 24232
Reputation: 1
If you are using MinGW64 with MSYS2, install glfw
library in your compiler. Open MSYS2 MINGW64 console and put:
pacman -S mingw-w64-x86_64-glfw
then compile your project using the following flags: -lglfw3 -lkernel32 -lopengl32 -lglu32
Upvotes: 0
Reputation: 11
I created makefile, it's for C, but you can edit it:
all:
gcc -I ./include ./src/*.c -L ./lib -lglfw3dll -lopengl32 -lmingw32 -lgdi32 -luser32 -lkernel32 -lglew32 -o ./bin/main
openglfolder:.
│
makefile
│
├───bin
│ glew32.dll
│ glfw3.dll
│ main.exe
│
├───include
│ eglew.h
│ glew.h
│ glfw3.h
│ glxew.h
│ wglew.h
│
├───lib
│ glew32.dll
│ glew32.lib
│ glew32s.lib
│ libglfw3.a
│ libglfw3dll.a
│
└───src
main.c
edit : this works only for windows
Upvotes: 0
Reputation: 1884
Download the binaries here according to your environment.
Project
+- glfw3.dll (You can put it in System32 or SysWOW64 instead.)
+- main.cpp
MinGW
+- include
| +- GLFW
| +- glfw3.h
+- lib
+- libglfw3.a
+- libglfw3dll.a (Renamed from glfw3dll.a)
g++ -c main.cpp
g++ -o main.exe main.o -lglfw3dll -lopengl32
Upvotes: 12