我正在尝试在Dev C ++上运行openGL。我无法运行代码。我已尝试过这个网站上的所有内容:
http://www.prinmath.com/csci5229/misc/DevC_OpenGL_for_Windows.pdf
我的操作系统是Windows 7-64位。如果可以,我会使用不同的IDE,但我的学校坚持使用Dev C ++。
这是我要尝试运行的代码:
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
void init()
{
glClearColor (1.0, 1.0, 1.0, 0.0);
glMatrixMode (GL_PROJECTION);
gluOrtho2D (0.0, 200.0, 0.0, 200.0);
}
void lineSegment()
{
glClear (GL_COLOR_BUFFER_BIT); // Clear display window. color buffer
glColor3f (0.0, 0.0, 0.0);
int p1 [ ] = {40,80};
int p2 [ ] = {160, 80};
int p3 [ ] = {100, 40};
int p4 [ ] = {100, 160};
int p5 [ ] = {0, 80};
int p6 [ ] = {200, 200};
int p7 [ ] = {100, 0};
int p8 [ ] = {100,200 };
int p9 [ ] = {30, 30};
int p10 [ ] = {0, 0};
glBegin(GL_LINE_LOOP);
glVertex2iv(p1);
glVertex2iv(p2);
glVertex2iv(p3);
glVertex2iv(p4);
glFlush ( );
}
int main(int argc, char *argv[])
{
glutInit (&argc, argv); // Initialize GLUT.
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); // Set display mode, single buffering.
glutInitWindowPosition (50, 100); // Set top-left display-window position.
glutInitWindowSize (400, 300); // Set display-window width and height.
glutCreateWindow ("An Example OpenGL Program"); // Create display window.
init( ); // Execute initialization procedure.
glutDisplayFunc (lineSegment); // Send graphics to display window.
glutMainLoop ( ); // Display everything and wait.
//return EXIT_SUCCESS();
return 0;
}
以下是我尝试编译时编译日志所说的内容:
gcc.exe -D__DEBUG__ -c testLab.c -o testLab.o -I"C:/Dev-Cpp/include" -pg -g3
windres.exe -i testProject_private.rc --input-format=rc -o testProject_private.res -O coff
gcc.exe -D__DEBUG__ testLab.o testProject_private.res -o "testProject.exe" -L"C:/Dev-Cpp/lib" -mwindows -lglut32 -lglu32 -lopengl32 -lwinmm -lgdi32 -lgmon -pg -g3
/mingw/lib/gcc/mingw32/../../../mingw32/lib/crt2.o(.text+0x18a)C:\Dev-Cpp\Bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: Dwarf Error: found dwarf version '4', this reader only handles version 2 information.
:crt1.c: undefined reference to `__dyn_tls_init_callback'
/mingw/lib/gcc/mingw32/../../../mingw32/lib/crt2.o(.text+0x1be):crt1.c: undefined reference to `__cpu_features_init'
/mingw/lib/gcc/mingw32/../../../mingw32/lib/crt2.o(.text+0x1f1):crt1.c: undefined reference to `__chkstk_ms'
/mingw/lib/gcc/mingw32/../../../mingw32/lib/crt2.o(.text+0x376):crt1.c: undefined reference to `__mingw_glob'
/mingw/lib/gcc/mingw32/../../../mingw32/lib/crt2.o(.text+0x47d):crt1.c: undefined reference to `__mingw_glob'
testLab.o(.text+0x26): In function `glutInit_ATEXIT_HACK':
C:/Dev-Cpp/include/GL/glut.h:455: undefined reference to `_imp____glutInitWithExit@12'
testLab.o(.text+0x52): In function `glutCreateWindow_ATEXIT_HACK':
C:/Dev-Cpp/include/GL/glut.h:472: undefined reference to `_imp____glutCreateWindowWithExit@8'
testLab.o(.text+0x7e): In function `glutCreateMenu_ATEXIT_HACK':
C:/Dev-Cpp/include/GL/glut.h:518: undefined reference to `_imp____glutCreateMenuWithExit@8'
testLab.o(.text+0x26a): In function `main':
C:/Users/../testLab.c:43: undefined reference to `_imp__glutInitDisplayMode@4'
testLab.o(.text+0x283):C:/Users/../testLab.c:44: undefined reference to `_imp__glutInitWindowPosition@8'
testLab.o(.text+0x29c):C:/Users/../testLab.c:45: undefined reference to `_imp__glutInitWindowSize@8'
testLab.o(.text+0x2c1):C:/Users/../testLab.c:49: undefined reference to `_imp__glutDisplayFunc@4'
testLab.o(.text+0x2cb):C:/Users/../testLab.c:50: undefined reference to `_imp__glutMainLoop@0'
collect2: ld returned 1 exit status
make.exe: *** [testProject.exe] Error 1
Execution terminated
答案 0 :(得分:1)
看起来你正在使用错误版本的C-runtime(CRT)进行链接。
PATH
环境变量,MINGW_HOME
环境变量和Dev-C ++编译器选项)。您必须使用随编译器提供的CRT。#include <windows.h>
。它可以修复dllimports
内容-m32
标志添加到编译器命令行(如果您使用64位编译器进行编译,它将为x86_32发出代码)请注意,Dev-C++ was released 22.02.2005的最新版本。它包括GCC 3.4.2 released September 6, 2004。你必须真的问你的老师为什么他们会坚持使用9岁的IDE和10年的编译器。 你可以找到Dev-C ++ here的维护版本(它被其他开发人员选中)和最新的MinGW编译器here。