OpenGL / GLUT - 大量未定义的引用
OpenGL / GLUT - lots of undefined references
我已经开始在 C++ (MinGW) 中使用 OpenGL 和 GLUT。我尝试了很多 GLUT 文件,但目前我正在使用 these files。我已经按照它所说的所有说明进行操作,但我仍然收到这些错误(请参阅输出)。
#include<windows.h>
#include<GL/glut.h>
#include<dos.h> // i know I shouldn't be using this
void render(void);
void keyboard(unsigned char c, int x, int y);
void mouse(int button, int state, int x, int y);
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(10, 10);
glutInitWindowSize(800, 600);
glutCreateWindow("Parmu Game Engine (Yes I didn't think of a better name.)");
// glutClearColor(0.0, 0.0, 0.0, 0.0);
glutDisplayFunc(render);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop();
}
void render(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLES); // ORIGIN AT CENTRE
glColor3f(1, 0, 0);
glVertex2f(0.3, 0.1);
glColor3f(0, 1, 0);
glVertex2f(0.8, 0.1);
glColor3f(0, 0, 1);
glVertex2f(0.5, 0.5);
glEnd();
// glFlush();
glutSwapBuffers();
}
void keyboard(unsigned char c, int x, int y)
{
if(c == 'q')
exit(0);
}
void mouse(int button, int state, int x, int y)
{
if(button == GLUT_RIGHT_BUTTON)
exit(0);
}
这是 cmd 运行 时的输出:
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
请注意,我的代码中没有使用任何 IDE。我使用 atom 进行编码,使用 cmd 进行 运行.
我已经在 PATH 中包含了 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.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
我已经开始在 C++ (MinGW) 中使用 OpenGL 和 GLUT。我尝试了很多 GLUT 文件,但目前我正在使用 these files。我已经按照它所说的所有说明进行操作,但我仍然收到这些错误(请参阅输出)。
#include<windows.h>
#include<GL/glut.h>
#include<dos.h> // i know I shouldn't be using this
void render(void);
void keyboard(unsigned char c, int x, int y);
void mouse(int button, int state, int x, int y);
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(10, 10);
glutInitWindowSize(800, 600);
glutCreateWindow("Parmu Game Engine (Yes I didn't think of a better name.)");
// glutClearColor(0.0, 0.0, 0.0, 0.0);
glutDisplayFunc(render);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop();
}
void render(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLES); // ORIGIN AT CENTRE
glColor3f(1, 0, 0);
glVertex2f(0.3, 0.1);
glColor3f(0, 1, 0);
glVertex2f(0.8, 0.1);
glColor3f(0, 0, 1);
glVertex2f(0.5, 0.5);
glEnd();
// glFlush();
glutSwapBuffers();
}
void keyboard(unsigned char c, int x, int y)
{
if(c == 'q')
exit(0);
}
void mouse(int button, int state, int x, int y)
{
if(button == GLUT_RIGHT_BUTTON)
exit(0);
}
这是 cmd 运行 时的输出:
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
请注意,我的代码中没有使用任何 IDE。我使用 atom 进行编码,使用 cmd 进行 运行.
我已经在 PATH 中包含了 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.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