OpenGL中无法解析的外部符号 __imp____glutInitWithExit@12和__imp____glutCreateWindowWithExit@8

本文详细介绍了在使用OpenGL和glut库进行开发时,在vs2010环境下遇到的链接错误问题,并提供了有效的解决方案。通过在`#include<glut.h>`前加入`#defineGLUT_DISABLE_ATEXIT_HACK`指令,可以成功解决错误。此教程适用于需要在vs2010中集成OpenGL和glut库的开发者。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    在OpenGL中使用glut库的时候,突然遇到以下错误:

   1>framebuffer.obj : error LNK2019: 无法解析的外部符号 __imp____glutInitWithExit@12,该符号在函数 _glutInit_ATEXIT_HACK@8 中被引用
     1>framebuffer.obj : error LNK2019: 无法解析的外部符号 __imp____glutCreateWindowWithExit@8,该符号在函数 _glutCreateWindow_ATEXIT_HACK@4 中被引用
     1>F:\project\framebuffer\Debug\framebuffer.exe : fatal error LNK1120: 2 个无法解析的外部命令

   解决方法:在#include<glut.h>的前面加上一句话即可:

   #define GLUT_DISABLE_ATEXIT_HACK


   注:程序环境是在vs2010中,win32控制台应用程序

g++ -std=c++17 -Wall -Wextra -g -Iinclude -c -MMD src/main.cpp -o src/main.o g++ -std=c++17 -Wall -Wextra -g -Iinclude -o output\main.exe src/main.o -Llib -lglad -lglfw3dll d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: src/main.o: in function `glutInit_ATEXIT_HACK': D:\opengl\GC/include/GL/freeglut_std.h:637: undefined reference to `_imp____glutInitWithExit@12' d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: src/main.o: in function `glutCreateWindow_ATEXIT_HACK': D:\opengl\GC/include/GL/freeglut_std.h:639: undefined reference to `_imp____glutCreateWindowWithExit@8' d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: src/main.o: in function `glutCreateMenu_ATEXIT_HACK': D:\opengl\GC/include/GL/freeglut_std.h:641: undefined reference to `_imp____glutCreateMenuWithExit@8' d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: src/main.o: in function `Z9myDrawingv': D:\opengl\GC/src/main.cpp:9: undefined reference to `glClearColor@16' d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: D:\opengl\GC/src/main.cpp:10: undefined reference to `glClear@4' d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: D:\opengl\GC/src/main.cpp:13: undefined reference to `glRotatef@16' d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: D:\opengl\GC/src/main.cpp:14: undefined reference to `_imp__glutWireTeapot@8' d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: D:\opengl\GC/src/main.cpp:17: undefined reference to `glFlush@0' d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: src/main.o: in function `main': D:\opengl\GC/src/main.cpp:24: undefined reference to `_imp__glutInitDisplayMode@4' d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: D:\opengl\GC/src/main.cpp:28: undefined reference to `_imp__glutDisplayFunc@4' d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: D:\opengl\GC/src/main.cpp:33: undefined reference to `_imp__glutMainLoop@0' collect2.exe: error: ld returned 1 exit status Makefile:78: recipe for target 'main.exe' failed
最新发布
06-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值