调用gluPerspective和gluLookAt给了我一个不确定的参考
Calling gluPerspective and gluLookAt gives me an undefined reference?
我正在尝试以下来源,来自Instant Glew:
#include <GL/glew.h>
#include <GL/freeglut.h>
#include <GL/glu.h>
#include <GL/gl.h>
void initGraphics()
{
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
const float lightPos[4] = {1, .5, 1, 0};
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
glEnable(GL_DEPTH_TEST);
glClearColor(1.0, 1.0, 1.0, 1.0);
}
void onResize(int w, int h)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, w, h);
gluPerspective(40, (float) w / h, 1, 100);
glMatrixMode(GL_MODELVIEW);
}
void onDisplay()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(0.0, 0.0, 5.0,
0.0, 0.0, 1.0,
0.0, 1.0, 0.0);
glutSolidTeapot(1);
glutSwapBuffers();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE);
glutInitWindowSize(500, 500);
glutCreateWindow("Teapot");
initGraphics();
glutDisplayFunc(onDisplay);
glutReshapeFunc(onResize);
glutMainLoop();
return 0;
}
我的构建设置是Windows 10 VSCode,带有MSYS2,以及如下所示的Makefile:
OBJS = 01-teapot.cpp
OBJ_NAME = C:/<"MyProjectPath">/build/01-teapot
INC_PATH = -IC:/msys64/mingw64/include/GL -LC:/msys64/mingw64/include/GL
INC_LINK_LIBS = -lglew32 -lopengl32 -lfreeglut
compiling :
g++ -Wall $(OBJS) $(INC_PATH) $(INC_LINK_LIBS) -o $(OBJ_NAME) -g
但输出是这样的:
C:Users<"myUser">AppDataLocalTempcc5d3AtP.o: In function `onResize(int, int)':
c:<"MyProjectPath">PaPu_Instant_GLEW/01-teapot.cpp:22: undefined reference to `gluPerspective'
C:Users<"myUser">AppDataLocalTempcc5d3AtP.o: In function `onDisplay()':
c:<"MyProjectPath">PaPu_Instant_GLEW/01-teapot.cpp:31: undefined reference to `gluLookAt'
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:32: compilando] Error 1
我真的不知道我在哪里失败了。我忘了链接一些库吗?我已经尝试在链接的库上添加-lglut -lGLU
,但编译器找不到它......
gluLookAt
是 GL Utility 库中的函数。您需要在链接器选项中包含-lglu32
。这在将 GLUT 与 MinGW 一起使用中进行了解释。
你给库的顺序也很重要;请参阅我的相关答案以供参考。在您的情况下,请将glfw3
替换为 freeglut
。
我相信您正在使用GLUT和GLU来学习OpenGL,这没关系,但请注意,它们当时是OpenGL 1的一部分,但不再是OpenGL不可或缺的一部分,并且已被弃用。 如果你正在做生产级的工作,我建议使用更成熟的库,如GLFW(而不是GLUT/FreeGLUT(;GLM具有GLU提供的所有便利功能。 请看达顿沃尔夫的回答。
相关文章:
- 我们可以访问一个不存在的联盟的成员吗
- 不确定要在我的main中放入什么才能使我的代码正常工作
- 不确定如何装饰我的C++库代码以在 C 中使用
- C++功能泄漏内存,我是C++新手,不确定如何解决
- "错误 C0000:语法错误,令牌"<EOF>"处出现意外$end,并且不确定
- 在C++中做一个场景问题,我不确定如何处理布尔和if循环
- 调用gluPerspective和gluLookAt给了我一个不确定的参考
- 我一直得到一个期望;错误,我不确定为什么
- 我得到一个无限的循环,我不确定为什么或如何修复它
- 我正在尝试在字符数组的中间添加一个空格.不确定如何正确移动它
- 试图在每次输出后使用一个函数摆脱'0',但不确定我可以返回什么
- 不确定这两个循环中的一个如何产生正确的输出
- 第一个C 库:我不确定在哪里参考并声明我的变量
- 为什么它不是一个不确定的循环,因为循环计数器在整数变量的范围之外
- 不确定如何使用另一个类中的对象创建带有参数的构造函数
- 如何在c++中生成一个变量的不确定类型
- 遇到错误问题:在'{'之前,预期的非限定 id 只是一个我需要的类的标头,只是不确定导致错误的原因
- 我正在创建一个双链接列表,它将按字母顺序排列姓名列表,但我不确定在int main()函数中放入什么
- 指向从另一个结构创建的数组的指针(不确定措辞是否正确)C++
- 提供一个不确定的生命周期bool在线程之间共享的最简单的方法是什么?