其他分享
首页 > 其他分享> > 如何在c-free(mingw)中创建OPENGL工程(汇总帖)

如何在c-free(mingw)中创建OPENGL工程(汇总帖)

作者:互联网

1.下载
第一入口
http://www.opengl.org/resources/libraries/glut/
可以从上述网站转到下面的地址:
http://user.xmission.com/~nate/glut.html
下载glut-bin包,内含glut32.dll、glut.h、glut32.lib。
此外可以从http://web.cs.wpi.edu/~gogo/courses/mingw/winglut.zip下载包含libglut32.a的版本,并将包里的libglut32win.a改名为libglut32.a即可。

2.安装
将glut32.dll复制到windows\system32目录下
将glut.h复制到mingw\include\gl目录下
将glut32.lib或libglut32.a复制到mingw\lib目录下(注:因为c-free 5中的mingw已经包含了libglut32.a,所以这步可以省略)

3.创建
工程 -> 新建 -> graphics -> glut project
填写工程名称,选择空的程序或DEMO,
glut's location 选择c-free 5\mingw\即可

4.注意事项
如果是按上述步骤创建的工程,默认使用的是c语言文件,如果要使用.cpp文件,那么只需要创建一个.cpp文件并添加到工程中即可。
但是,在mingw下用c++创建glut工程会有一些小问题,最常见的就是报错
[Error] ... error: redeclaration of C++ built-in type `short'
这时,必须将#include <windows.h>添加在#include <GL/glut.h>之前。

ps.自己搜索资料找到的上述方法,结果在www.mingw.org上发现了更全面的英文版
(不好意思我就直接复制粘贴了,方便查询):
HOWTO Use Mark J. Kilgard's OpenGL Utility Toolkit (GLUT) with MinGW

http://www.opengl.org/resources/libraries/glut/

Posted August 2nd, 2008 by earnie
mingw opengl
Download the binary and unpack the binary distribution of Nate Robins' Win32 port of GLUT. These instructions are based on version 3.7.6 and may not work with earlier or newer versions.
Create a subdirectory called GL in your project's include directory, and copy the file =glut.h= from the package there.
Copy the library, glut32.lib, to your project's build directory.
Copy the DLL, glut32.dll, to the same directory where your project's executable will be created.
Ensure that you're using binutils 2.16.91 or later.
Define the macros _STDCALL_SUPPORTED and _M_IX86 before including <GL/glut.h> in your source code. Three ways you can do this are:
on the command line with -D_STDCALL_SUPPORTED -D_M_IX86
use macro defintions in your source code (eg. #define _STDCALL_SUPPORTED)
include <windows.h> before including <GL/glut.h>
Compile your project, ensuring that <GL/glut.h> is in the include path, and that you're linking with glut32.lib.

When distributing any applications you built using GLUT, you need include a copy of glut32.dll in your distribution. This is not a standard Windows DLL so you can't expect your users to already have it installed on their systems. You should install glut32.dll in same directory as your application's executable. This ensures that other applications won't install a buggy or incompatible version of the GLUT DLL over yours.
Errors you may get:
E:\TEMP/ccwosggb.o:t10.c:(.text+0x1c): undefined reference to `__glutInitWithExit'
E:\TEMP/ccwosggb.o:t10.c:(.text+0x37): undefined reference to `__glutCreateWindowWithExit'
E:\TEMP/ccwosggb.o:t10.c:(.text+0x52): undefined reference to `__glutCreateMenuWithExit'
E:\TEMP/ccwosggb.o:t10.c:(.text+0x15a): undefined reference to `glutDisplayFunc'
E:\TEMP/ccwosggb.o:t10.c:(.text+0x15f): undefined reference to `glutMainLoop'
...

This indicates that you didn't define _STDCALL_SUPPORTED before including <GL/glut.h>. See the instructions above on different ways you can do this.
E:\TEMP/ccMMoggb.o(.text+0x1c):t10.c: undefined reference to `__glutInitWithExit@12'
E:\TEMP/ccMMoggb.o(.text+0x3e):t10.c: undefined reference to `__glutCreateWindowWithExit@8'
E:\TEMP/ccMMoggb.o(.text+0x60):t10.c: undefined reference to `__glutCreateMenuWithExit@8'
E:\TEMP/ccMMoggb.o(.text+0x1a5):t10.c: undefined reference to `glutDisplayFunc@4'
E:\TEMP/ccMMoggb.o(.text+0x1ad):t10.c: undefined reference to `glutMainLoop@0'
...

This indicates you're using an older version of binutils. Upgrade to 2.16.91.
E:\TEMP/ccMMoggb.o(.text+0x1c):t10.c: undefined reference to `__glutInitWithExit@12'
E:\TEMP/ccMMoggb.o(.text+0x3e):t10.c: undefined reference to `__glutCreateWindowWithExit@8'
E:\TEMP/ccMMoggb.o(.text+0x60):t10.c: undefined reference to `__glutCreateMenuWithExit@8'

If these are the only three undefined references then you probably linked with -lglut32 instead of glut32.lib.
./GL/glut.h:58: warning: ignoring #pragma comment
./GL/glut.h:66: warning: ignoring #pragma comment
./GL/glut.h:67: warning: ignoring #pragma comment
./GL/glut.h:68: warning: ignoring #pragma comment
./GL/glut.h:76: warning: ignoring #pragma warning
./GL/glut.h:77: warning: ignoring #pragma warning

These warnings are harmless, but you can define the macros GLUT_NO_LIB_PRAGMA and GLUT_NO_WARNING_DISABLE before including <GL/glut.h> to prevent them.
./GL/glut.h:549: warning: 'glutCreateMenu_ATEXIT_HACK' defined but not used

This warning is also harmless, but I'm not sure of any safe way to prevent it without modifying =<GL/glut.h>=.
Login or register to post comments 41796 reads
procedure entry point could not be located in dll
On August 27th, 2008 cweb says:

Perhaps this can help someone who had a similar problem. I was trying to call the DevIL libraries though.

(Under XP) If you are trying to call a library / dll from c++ / mingw and you get the
runtime error, "procedure entry point could not be located in .... .dll", recreate the .a files using dlltool
in this way.

dlltool -k -D DevIL.dll -d DevIL.def -l libDevIL.a
do the same for all dll's.

The other syntax for dlltool does not seem to work (you get the error above).

I hope this helps someone.
Login or register to post comments
Site Status

Site maintenance completed May 25th, 2012 at 12:38 UTC

转载于:https://www.cnblogs.com/ifstudios/archive/2012/08/08/2628890.html

标签:undefined,TEMP,OPENGL,text,glut,free,mingw,t10,reference
来源: https://blog.csdn.net/weixin_33835690/article/details/94278602