Question

I am programming since a few days and I simply want to open a window with opengl. I got glew and glfw, I linked the library of glew and the headers of both but when I compile I get an error. I've got windows7. I use def c++.

This is the code:

#define GLEW_NO_GLU
#define GLFW_NO_GLU

#include <GL/glew.h>
#include <GLFW/glfw3.h>


int main() {
GLFWwindow* window1 = glfwCreateWindow(640, 480, "window1", NULL, NULL);
glfwMakeContextCurrent(window1);
return 0;
}

And this are the errors:

C:\Users\Stefan\Desktop\Programmieren\Code\c++_Projekt2_OpenGL\main.o   In function `main':
C:\Users\Stefan\Desktop\Programmieren\Code\c++_Projekt2_OpenGL\main.cpp undefined reference to `glfwCreateWindow'
C:\Users\Stefan\Desktop\Programmieren\Code\c++_Projekt2_OpenGL\main.cpp undefined reference to `glfwMakeContextCurrent'
C:\Users\Stefan\Desktop\Programmieren\Code\c++_Projekt2_OpenGL\collect2.exe [Error] ld returned 1 exit status

This is the compiler log or however it is called:

Compiler: TDM-GCC 4.7.1 32-bit Release
Building Makefile"C:\Users\Stefan\Desktop\Programmieren\Code\c++_Projekt2_OpenGL\Makefile.win"
Führe  make... aus
mingw32-make.exe -f "C:\Users\Stefan\Desktop\Programmieren\Code\c++_Projekt2_OpenGL\Makefile.win" all
g++.exe -D__DEBUG__ main.o -o Projekt2.exe -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib32" -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib32" -static-libgcc glew-1.10.0/lib/Release/Win32/glew32.lib -m32 -g3

main.o: In function `main':
C:\Users\Stefan\Desktop\Programmieren\Code\c++_Projekt2_OpenGL/main.cpp:9: undefined reference to `glfwCreateWindow'
C:\Users\Stefan\Desktop\Programmieren\Code\c++_Projekt2_OpenGL/main.cpp:10: undefined reference to `glfwMakeContextCurrent'
collect2.exe: error: ld returned 1 exit status

mingw32-make.exe: *** [Projekt2.exe] Error 1

Compilation failed after 0,14 seconds with errors
Était-ce utile?

La solution

From the log messages you posted, it seems that you haven't configured your Dev-C++ project properly to link against glfw:

g++.exe -D__DEBUG__ main.o -o Projekt2.exe -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib32" -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib32" -static-libgcc glew-1.10.0/lib/Release/Win32/glew32.lib -m32 -g3

The glfw library is missing, that is why you're getting an undefined reference to its functions. You should set up it as you did with glew32.

Also, the link to What is an undefined reference/unresolved external symbol error and how do I fix it?, provided in the comments to your question, is worth the read.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top