使用 GLUT 未定义的引用

发布于 2024-12-25 08:18:26 字数 2499 浏览 2 评论 0原文

我一直在使用 SDL 成功地学习 OpenGL,但是我正在遵循使用 GLUT 的教程,并且我尝试切换到 GLUT,因为它看起来对新手来说更容易使用,而且我觉得我会更快地掌握内容。我认为这将是一个简单快速且无痛的过程,但是在尝试编译 GLUT 内容(使用 MinGW)时遇到以下问题 (我已经下载了 GLUT 并将头文件提取到我的包含文件中,因此它被正确包含,并且我还将 lib 文件提取到 lib 文件夹中,并且我正在链接它,用于 glut 的 .DLL 存在于我的system32 因此它被成功调用。

我对我做错了什么一无所知,并感谢任何帮助和建议

在编译以下一小段内容时构建消息(目前不会执行任何操作,但应该执行任何操作)编译):

#include <stdlib.h>
#include <GL/glut.h>

static int day = 0, year = 0;

void init()

{

glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_FLAT);

}

void display(void)

{

glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);

glPushMatrix();
glutWireSphere(1.0,20,16);
glRotatef((GLfloat) year, 0.0,1.0,0.0);
glTranslatef(2.0,0.0,0.0);
glRotatef((GLfloat) day, 0.0, 1.0, 0.0);
glutWireSphere(0.2,10,8);
glPopMatrix();
glutSwapBuffers();

}

//void reshape(int w, int h)

int main(int argc, char **argv)

{



}

生成器错误:

C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to    `__glutInitWithExit'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `__glutCreateWindowWithExit'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `__glutCreateMenuWithExit'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glClearColor'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glShadeModel'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glClear'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glColor3f'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glPushMatrix'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `glutWireSphere'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glRotatef'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glTranslatef'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glRotatef'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `glutWireSphere'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glPopMatrix'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `glutSwapBuffers'|
||=== Build finished: 15 errors, 0 warnings ===|

I have been using SDL with success to learn OpenGL, however I am following tutorials that are using GLUT and I attempted to switch over to GLUT because it looks easier to use for novices and I feel I would pick the content up quicker. I thought this would be a simple quick and painless process, however I am running into the following problem when attempting to compile GLUT content (using MinGW)
(I've downloaded GLUT and extracted the header file to my includes so it is being included correctly, and I have also extracted the lib files to the lib folder and I'm linking against it, the .DLL for glut is present in my system32 so it is being called successfully.

I'm clueless as to what I am doing wrong and would be grateful for any help and suggestions

Build messages when compiling the following small piece of content (which won't do anything at the moment but should compile):

#include <stdlib.h>
#include <GL/glut.h>

static int day = 0, year = 0;

void init()

{

glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_FLAT);

}

void display(void)

{

glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);

glPushMatrix();
glutWireSphere(1.0,20,16);
glRotatef((GLfloat) year, 0.0,1.0,0.0);
glTranslatef(2.0,0.0,0.0);
glRotatef((GLfloat) day, 0.0, 1.0, 0.0);
glutWireSphere(0.2,10,8);
glPopMatrix();
glutSwapBuffers();

}

//void reshape(int w, int h)

int main(int argc, char **argv)

{



}

Builder Errors:

C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to    `__glutInitWithExit'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `__glutCreateWindowWithExit'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `__glutCreateMenuWithExit'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glClearColor'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glShadeModel'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glClear'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glColor3f'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glPushMatrix'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `glutWireSphere'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glRotatef'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glTranslatef'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glRotatef'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `glutWireSphere'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `_imp__glPopMatrix'|
C:\Documents and Settings\User\Desktop\test.o:test.cpp|| undefined reference to `glutSwapBuffers'|
||=== Build finished: 15 errors, 0 warnings ===|

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ぺ禁宫浮华殁 2025-01-01 08:18:26

是的,我必须包含这段代码才能使其在 Windows 上运行。

#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#endif

Windows上的链接器似乎通过windows.h链接来访问System32中的.dll文件

Yes, I had to include this piece of code to get it to work on windows.

#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#endif

It seems linker on windows links through windows.h to access the .dll files in System32

人心善变 2025-01-01 08:18:26

不,您不是针对 glut 进行链接(也不是针对 gl )。或者这是一个糟糕的版本,但我对此表示怀疑。您可以尝试发布您的项目配置或 Makefile。显然,_imp__gl* 的东西是 libGL,而 glut* 的东西是 glut。另外,请确保您链接的库格式是链接器可以理解的。 *.lib 文件通常是 MS-COFF 格式,这是 Microsoft 自己的 COFF 标准风格。 mingw (ld) 中的链接器将无法链接此文件。您需要一个带有 .a 扩展名(通常)的静态库。

No, you aren't linking against glut (nor gl for that matter). Or it is a bad version, but I doubt that. You can try posting your project configuration or Makefile. The _imp__gl* things are libGL, and glut* things are glut, obviously. Also, make sure that you are linking against a library format that your linker understands. *.lib files are typically MS-COFF format, which is Microsoft's own flavor of the COFF standard. The linker in mingw (ld) won't be able to link this file. You need a static library with the .a extension (typically).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文