This question already has an answer here:
这个问题已经有了答案:
- What is an undefined reference/unresolved external symbol error and how do I fix it? 27 answers
- 什么是未定义的引用/未解决的外部符号错误,如何修复它?27日答案
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++.
我从几天后就开始编程了,我只是想打开一个opengl的窗口。我得到了glew和glfw,我链接了glew的库和两者的头,但是当我编译时,我得到了一个错误。我有windows7多。我使用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
1 个解决方案
#1
0
From the log messages you posted, it seems that you haven't configured your Dev-C++ project properly to link against glfw
:
从您发布的日志消息中,似乎您还没有正确地配置devc ++项目来链接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
.
glfw库丢失了,这就是为什么您对它的函数有一个未定义的引用。你应该像对待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.
另外,链接到未定义的引用/未解决的外部符号错误,以及如何修复它?在对你的问题的评论中提供的,是值得一读的。
#1
0
From the log messages you posted, it seems that you haven't configured your Dev-C++ project properly to link against glfw
:
从您发布的日志消息中,似乎您还没有正确地配置devc ++项目来链接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
.
glfw库丢失了,这就是为什么您对它的函数有一个未定义的引用。你应该像对待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.
另外,链接到未定义的引用/未解决的外部符号错误,以及如何修复它?在对你的问题的评论中提供的,是值得一读的。