本文介绍了在Cygwin下编译最小的GLEW应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 让我们考虑下面的程序,并尝试在Cygwin下编译它: #include< GL / glut.h> int main(int argc,char ** argv) { glutInit(& argc,argv); glLoadIdentity(); } 它编译和运行很好。 -I / usr / include / opengl 似乎非常重要。 g ++ -I / usr / include / opengl -I ../include / cygwin -L ../ lib / cygwin test.cpp -o test.exe -lglut32 -lglu32 -lglew32 -lopengl32 现在, #include< ; GL / glew.h> // from newest NVIDIA SDK #include< GL / glut.h> int main(int argc,char ** argv) { glewInit(); glutInit(& argc,argv); glLoadIdentity(); } 由编译 g ++ -I / usr / include / opengl -I ../include/cygwin -L ../ lib / cygwin test.cpp -o test.exe -lglut32 -lglu32 -lglew32 - lopengl32 失败。 如何构建第二个应用程序? 第一 从NVIDIA SDK:由VS,由cygwin,由cygwin与-D_WIN32。我也尝试了cygwin从源码创建原始的glew。 VS build给予 /cygdrive/c/DOCUME~1/kelebron/LOCALS~1/Temp/ccErbecl.o:test.cpp :(。text + 0xa8):未定义的引用`_glLoadIdentity' collect2:ld返回1退出状态 cygwin构建许多 ../ lib / cygwin / glew32.lib(glew.o):glew.c :(。text + 0x38e):未定义引用`_glXGetProcAddress' 和cygwin与-D_WIN32根本不编译(我有点动机的 this post )。 第二 似乎有两种方法可以与OpenGL连接 与-L / lib / w32api 或-L / usr / X11R6 / lib -lX11 -lXi -lXmu 但是,-L指令不会更改任何内容。我有/usr/lib/w32api/libopengl32.a,但可能会缺少X11版本(/ usr / X11R6 / lib / libGL?)。我应该将什么包装到Cygwin中?我已经安装了所有从libGL开始(不仅...)。解决方案我发现有两种方法可以在Cygwin下编译opengl代码。 第一个链接到本地​​win32api库glut32 glu32 opengl32(也是glui)。 这些有点老: glut v3.7.6 opengl v1.1 glui 2.11 第二种方式使用X11库glut glu gl。他们在他们的头文件中有更新的版本号(注意,使用GL扩展需要> v1.2): glut v4(freeglut) opengl v1.3 glext ... 所以要使用第一个选项comile与: -I / usr / include / opengl 并链接到: -lglut32 -lGLU32 -lOpenGL32 要使用X11版本,请使用: strong> -I / usr / include / (默认情况下包含) 并链接到: -lglut -lGLU -lGL (注意区别) br> 您可以添加X11标头和库,但我想他们被GL包括。 -I / usr / X11R6 / include -L / usr / X11R6 / lib -lXmu -lXi -lXext -lX11 在Cygwin安装程序中,以下包是您的选择: opengl - 给出win32版本的opengl,glut,glui libglut-devel 我还建议您包括 Xorg-server ,因为您将需要X服务器。 希望这有帮助。 Let's consider the following program and try to compile it under Cygwin:#include <GL/glut.h>int main(int argc, char** argv){ glutInit(&argc, argv); glLoadIdentity();}It compiles and runs just fine. -I/usr/include/opengl seems to be terribly important.g++ -I/usr/include/opengl -I../include/cygwin -L../lib/cygwin test.cpp -o test.exe -lglut32 -lglu32 -lglew32 -lopengl32Now,#include <GL/glew.h> // from newest NVIDIA SDK#include <GL/glut.h>int main(int argc, char** argv){ glewInit(); glutInit(&argc, argv); glLoadIdentity();}compiled byg++ -I/usr/include/opengl -I../include/cygwin -L../lib/cygwin test.cpp -o test.exe -lglut32 -lglu32 -lglew32 -lopengl32fails.How to build the second application?FirstThere are several ways to build glew by from NVIDIA SDK: by VS, by cygwin, by cygwin with -D_WIN32. I also tried cygwin build of original glew from source.VS build gives/cygdrive/c/DOCUME~1/kelebron/LOCALS~1/Temp/ccErbecl.o:test.cpp:(.text+0xa8): undefined reference to `_glLoadIdentity'collect2: ld returned 1 exit statuscygwin builds give many../lib/cygwin/glew32.lib(glew.o):glew.c:(.text+0x38e): undefined reference to `_glXGetProcAddress'and cygwin with -D_WIN32 does not compile at all (I was slightly motivated by this post).SecondThere seem to be two ways to link with OpenGLwith -L/lib/w32apior with -L/usr/X11R6/lib -lX11 -lXi -lXmuBut, the -L directives do not change anything. I've got /usr/lib/w32api/libopengl32.a, but may be missing the X11 version (/usr/X11R6/lib/libGL?). What package should I include into Cygwin? I've installed all starting with libGL (not only...). 解决方案 I had a similar issue a while ago, and I found that there are two ways to compile opengl code under Cygwin.The first links against the native win32api libraries glut32 glu32 opengl32 (also glui).Those are somewhat older: glut v3.7.6 opengl v1.1 glui 2.11The second way uses the X11 libraries glut glu gl. They have newer version number in their header files (Note that to use GL extensions requires >v1.2): glut v4 (freeglut) opengl v1.3 glext ...So to use the first option comile with: -I/usr/include/opengland link against: -lglut32 -lGLU32 -lOpenGL32To use the X11 version, compile with: -I/usr/include/ (which is included by default)and link with: -lglut -lGLU -lGL (note the difference)you could add the X11 headers and libraries but I guess their included by the GL ones.-I/usr/X11R6/include-L/usr/X11R6/lib -lXmu -lXi -lXext -lX11In the Cygwin installer, the following packages are your choices:opengl -- gives the win32 version of opengl, glut, gluilibglut-devel -- X11 version of glut (freeglut), this will also pick all dependent packages. (glproto, libGL libGLU, libX11, ...)I also recommend including the Xorg-server since you will need an X server.Hope this helps. 这篇关于在Cygwin下编译最小的GLEW应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-05 01:31