OpenGL/GLUT-大量未定义的引用 我已经开始使用C++中的GLUT(MinGW)来实现OpenGL。我尝试了很多GLUT文件,但目前我正在使用。我已经按照它所说的所有说明进行了操作,但仍然会遇到这些错误(请参见输出)

OpenGL/GLUT-大量未定义的引用 我已经开始使用C++中的GLUT(MinGW)来实现OpenGL。我尝试了很多GLUT文件,但目前我正在使用。我已经按照它所说的所有说明进行了操作,但仍然会遇到这些错误(请参见输出),c++,windows,opengl,glut,freeglut,C++,Windows,Opengl,Glut,Freeglut,应该注意的是,我的代码没有使用任何IDE。我使用atom编写代码,使用cmd运行 我已经在路径中包含了E:/mingw/bin 以下是我尝试过的命令: E:\Workspace_CPP\Atom\Parmu_Game_Engine>g++ main.cpp E:\Workspace_CPP\Atom\Parmu_Game_Engine>g++ main.cpp -lglut E:\Workspace_CPP\Atom\Parmu_Game_Engine>g++ main.c

应该注意的是,我的代码没有使用任何IDE。我使用atom编写代码,使用cmd运行

我已经在路径中包含了E:/mingw/bin

以下是我尝试过的命令:

E:\Workspace_CPP\Atom\Parmu_Game_Engine>g++ main.cpp

E:\Workspace_CPP\Atom\Parmu_Game_Engine>g++ main.cpp -lglut

E:\Workspace_CPP\Atom\Parmu_Game_Engine>g++ main.cpp -lglut -lGLU
E:\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot find -lGLU
collect2: ld returned 1 exit status

E:\Workspace_CPP\Atom\Parmu_Game_Engine>g++ main.cpp -lglut -lGLU - lGL
g++: lGL: No such file or directory
g++: -E or -x required when input is from standard input

E:\Workspace_CPP\Atom\Parmu_Game_Engine>g++ main.cpp -m32

E:\Workspace_CPP\Atom\Parmu_Game_Engine>g++ -c main.cpp -lglut32win
g++: -lglut32win: linker input file unused because linking not done
如文件所述,要链接的正确库包括

  • opengl32.lib-导入Windows OpenGL API库(使用
    -lopengl32

  • glu32.lib-为GLU的Windows实现导入库(使用
    -lglu32

  • GLUT库不随Windows提供,因此它取决于您从何处获得GLUT for Windows。在中的版本中,您需要链接glut32.lib,并确保在应用程序中包含glut32.dll


看看它是否起作用。谢谢你也可以把这个作为答案提交,这样我就可以接受了。
E:\Workspace_CPP\Atom\Parmu_Game_Engine>g++ main.cpp
C:\Users\Public\Documents\Wondershare\CreatorTemp/ccMBcaaa.o:main.cpp:(.text+0x1c): undefined reference to `__glutInitWithExit@12'
C:\Users\Public\Documents\Wondershare\CreatorTemp/ccMBcaaa.o:main.cpp:(.text+0x3d): undefined reference to `__glutCreateWindowWithExit@8'
C:\Users\Public\Documents\Wondershare\CreatorTemp/ccMBcaaa.o:main.cpp:(.text+0x5d): undefined reference to `__glutCreateMenuWithExit@8'
C:\Users\Public\Documents\Wondershare\CreatorTemp/ccMBcaaa.o:main.cpp:(.text+0xaf): undefined reference to `glutInitDisplayMode@4'
C:\Users\Public\Documents\Wondershare\CreatorTemp/ccMBcaaa.o:main.cpp:(.text+0xc6): undefined reference to `glutInitWindowPosition@8'
C:\Users\Public\Documents\Wondershare\CreatorTemp/ccMBcaaa.o:main.cpp:(.text+0xdd): undefined reference to `glutInitWindowSize@8'
C:\Users\Public\Documents\Wondershare\CreatorTemp/ccMBcaaa.o:main.cpp:(.text+0xfb): undefined reference to `glutDisplayFunc@4'
C:\Users\Public\Documents\Wondershare\CreatorTemp/ccMBcaaa.o:main.cpp:(.text+0x10a): undefined reference to `glutKeyboardFunc@4'
C:\Users\Public\Documents\Wondershare\CreatorTemp/ccMBcaaa.o:main.cpp:(.text+0x119): undefined reference to `glutMouseFunc@4'
C:\Users\Public\Documents\Wondershare\CreatorTemp/ccMBcaaa.o:main.cpp:(.text+0x121): undefined reference to `glutMainLoop@0'
C:\Users\Public\Documents\Wondershare\CreatorTemp/ccMBcaaa.o:main.cpp:(.text+0x13a): undefined reference to `glClear@4'
C:\Users\Public\Documents\Wondershare\CreatorTemp/ccMBcaaa.o:main.cpp:(.text+0x149): undefined reference to `glBegin@4'
C:\Users\Public\Documents\Wondershare\CreatorTemp/ccMBcaaa.o:main.cpp:(.text+0x16b): undefined reference to `glColor3f@12'
C:\Users\Public\Documents\Wondershare\CreatorTemp/ccMBcaaa.o:main.cpp:(.text+0x184): undefined reference to `glVertex2f@8'
C:\Users\Public\Documents\Wondershare\CreatorTemp/ccMBcaaa.o:main.cpp:(.text+0x1a6): undefined reference to `glColor3f@12'
C:\Users\Public\Documents\Wondershare\CreatorTemp/ccMBcaaa.o:main.cpp:(.text+0x1bf): undefined reference to `glVertex2f@8'
C:\Users\Public\Documents\Wondershare\CreatorTemp/ccMBcaaa.o:main.cpp:(.text+0x1e1): undefined reference to `glColor3f@12'
C:\Users\Public\Documents\Wondershare\CreatorTemp/ccMBcaaa.o:main.cpp:(.text+0x1fa): undefined reference to `glVertex2f@8'
C:\Users\Public\Documents\Wondershare\CreatorTemp/ccMBcaaa.o:main.cpp:(.text+0x202): undefined reference to `glEnd@0'
C:\Users\Public\Documents\Wondershare\CreatorTemp/ccMBcaaa.o:main.cpp:(.text+0x207): undefined reference to `glutSwapBuffers@0'
collect2: ld returned 1 exit status
E:\Workspace_CPP\Atom\Parmu_Game_Engine>g++ main.cpp

E:\Workspace_CPP\Atom\Parmu_Game_Engine>g++ main.cpp -lglut

E:\Workspace_CPP\Atom\Parmu_Game_Engine>g++ main.cpp -lglut -lGLU
E:\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot find -lGLU
collect2: ld returned 1 exit status

E:\Workspace_CPP\Atom\Parmu_Game_Engine>g++ main.cpp -lglut -lGLU - lGL
g++: lGL: No such file or directory
g++: -E or -x required when input is from standard input

E:\Workspace_CPP\Atom\Parmu_Game_Engine>g++ main.cpp -m32

E:\Workspace_CPP\Atom\Parmu_Game_Engine>g++ -c main.cpp -lglut32win
g++: -lglut32win: linker input file unused because linking not done