使用cmake和visual studio编译freeglut和glew源代码并配置的流程

1 下载

(1)CMake
我下载的版本是cmake-3.4.0-rc1-win32-86.exe。
(2)FreeGLUT
我下载的版本是Freeglut 3.0.0[Released: 7 March 2015]。
(3)GLEW(OpenGL Extension Wrangler)
我下载的版本是glew-1.13.0.zip。

可以找官网或者在CSDN上搜索下载。

2 编译FreeGLUT

CMake使用指南:

Download CMake (http://www.cmake.org/cmake/resources/software.html).
Get one of the releases from the binary distribution section.
Run the CMake installer, install wherever you like.
Launch CMake via Start > Program Files > CMake 2.8 > CMake (GUI)
(note that the shortcut put by the installer on your desktop does NOT point to the CMake GUI program!)
In the “Where is the source code” box, type or browse to the root directory of your freeglut source (so that’s /freeglut, not
/freeglut/src).
In the “Where to build the binaries” box, type or browse to any
folder you like - this will be where the Visual Studio solution will be generated. This folder does not have to exist yet.
Hit the Configure button near the bottom of the window.
Pick your target compiler, make sure that its installed on your
system of course!
Answer Ok when asked if you want to create the build directory.
Wait for the configure process to finish.
The screen will now have some configuration options on it, for
instance specifying whether you want to build static and/or shared libraries (see below for a complete list). When you’ve selected your options, click the Configure button again.
The Generate button at the bottom will now be enabled. Click Generate.
The build files will now be generated in the location you picked.
You can now navigate to the build directory you specified in step 5.
Open the freeglut.sln file that was generated in your build directory, and compile as usual.

在cmake产生的文件夹中运行freeglut.sln,release模式生成后

在bin/Release下找到freeglut.dll

在lib/Release下找到两个.lib

在原始下载文件夹中include文件夹下找到GL文件夹

3 编译GLEW

(1)将glew下载包解压缩后,依次打开build→vc12,用Visual Studio打开sln文件,将对所涉及的项目进行自动升级。
(2)根据red book示例代码的需要,对glew_static工程进行编译。由于该工程默认的生成库文件名称为glews.lib,需在编译之前在配置属性→常规→目标文件名中,将其改为glew_static。
(3)在bin\Release\Win32,lib\Release\Win32,include下找到.dll,.lib,GL文件夹

4 搬运头文件和库文件

(1)将GL文件夹搬至MSVC的包含目录,我的是“C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\GL”。
(2)将.lib库文件搬至MSVC的库目录,我的是“C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib”。
(3)将.dll文件搬至“C:\Windows\System32”和“C:\Windows\SysWOW64”。

注:该步的目的只是为了以后不用每次都修改项目属性,如果不需要也可以直接修改项目属性:项目右键-》属性-》VC++目录-》include目录/ library目录,并且将.dll文件放在项目生成的.exe文件同一目录下

5测试代码

为了测试是否安装成功,可建立一个简单的Win32 console工程测试。代码如下:

#include "stdafx.h"
#include 

void myDisplay(void)
{
    glClear(GL_COLOR_BUFFER_BIT);
    glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
    glFlush();
}

int main(int argc, char *argv[])
{
    glutInit(&argc, argv);;
    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
    glutInitWindowPosition(100, 100);
    glutInitWindowSize(400, 400);
    glutCreateWindow("First GLUT Sample");
    glutDisplayFunc(&myDisplay);
    glutMainLoop();
    return 0;
}

6其他问题

找不到文件“freeglutd.lib”:
如果你只有freeglut.lib而没有debug版的freeglutd.lib,并且切换到release下还是报这个错,那么可以在 项目属性-》C/C++-》预处理器(preprocessor)中添加一个宏NDEBUG

大量摘自:
http://blog.csdn.net/zhuxiaoyang2000/article/details/49158965

你可能感兴趣的:(配置)