首页 > 其他 > 详细

vc如何编译链接opengl库

时间:2014-03-09 05:05:03      阅读:673      评论:0      收藏:0      [点我收藏+]

 vc2012如何链接opengl库?

首先,我们需要下载opengl的库文件,http://pan.baidu.com/s/1kTsjkZP

找到vc2012的安装路径

.h文件扔到\VC\include中。 

.lib文件扔到\VC\lib中。

.dll文件扔到 c:\windows\system32中。

 


 

当我们编译发生以下错误时:

错误 1 error LNK2019: 无法解析的外部符号 __imp____glutInitWithExit@12,该符号在函数 _glutInit_ATEXIT_HACK@8 中被引用 
错误 2 error LNK2019: 无法解析的外部符号 __imp____glutCreateWindowWithExit@8,该符号在函数 _glutCreateWindow_ATEXIT_HACK@4 中被引用 
错误 3 error LNK1120: 2 个无法解析的外部命令

网络上最有效的解决方式:

刚好在#include<gl/glut.h>之前加上

#define GLUT_DISABLE_ATEXIT_HACK

 

 


 

无法解析的外部符号 __imp____glutCreateMenuWithExit@8:

Win32 项目中应用程序的入口函数为 WinMain (窗口应用程序的主函数).而 Win32控制台应用程序的入口函数为 main 函数,也就是普通的命令行应用程序的主函数。
所以在 Win32项目中, 没有写 WinMain 函数实现就会出现链接错误了。同样在 Win32 控制台应用程序中, 没有写 main 函数的实现也会出现连接错误一样。

我们需要写函数:

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow)

这个作为应用程序的入口函数(相当于控制台程序的main函数)

 

 

 


 

错误 1 error LNK1168: 无法打开 C:\Users\yejinru\Desktop\计算机图形学\Debug\计算机图形学.exe 进行写入 C:\Users\yejinru\Desktop\计算机图形学\计算机图形学\LINK 计算机图形学

遇到这种情况时,需要在任务管理器中手动把运行着的exe结束任务或者把项目暂停运行。

 

 

借别人的代码一用。。。原地址在:http://www.cppblog.com/wicbnu/archive/2010/09/30/128123.aspx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//#pragma comment(lib, "OpenGL32.lib")
//#pragma comment(lib, "GLU32.lib")
//#pragma comment(linker, "/subsystem:console")
 
#include "stdafx.h"
#include <windows.h>
#include <GL/glu.h>
#include <GL/gl.h>
#include <GL/glaux.h>
 
#define GLUT_DISABLE_ATEXIT_HACK
#include <GL/glut.h>
 
#include <iostream>
#include <cstring>
#include <cstdio>
 
 
void background(void){
 
//设置背景颜色为黑色
    glClearColor(0.0,0.0,0.0,0.0);
 
}
 
 
void myDisplay(void){
 
//buffer设置为颜色可写
 
    glClear(GL_COLOR_BUFFER_BIT);
 
//开始画三角形
 
    glBegin(GL_TRIANGLES);
 
//设置为光滑明暗模式
 
    glShadeModel(GL_SMOOTH);
 
//设置第一个顶点为红色
 
    glColor3f(1.0,0.0,0.0);
 
//设置第一个顶点的坐标为(-1.0,-1.0)
 
    glVertex2f(-1.0,-1.0);
 
//设置第二个顶点为绿色
 
    glColor3f(0.0,1.0,0.0);
 
//设置第二个顶点的坐标为(0.0,-1.0)
 
    glVertex2f(0.0,-1.0);
 
//设置第三个顶点为蓝色
 
    glColor3f(0.0,0.0,1.0);
 
//设置第三个顶点的坐标为(-0.5,1.0)
 
    glVertex2f(-0.5,1.0);
 
//三角形结束
 
    glEnd();
 
//强制OpenGL函数在有限时间内运行
 
    glFlush();
 
}
 
void myReshape(GLsizei w,GLsizei h){
 
    glViewport(0,0,w,h);
 
//设置视口
 
 
 
    glMatrixMode(GL_PROJECTION);
 
//指明当前矩阵为GL_PROJECTION
 
    glLoadIdentity();
 
//将当前矩阵置换为单位阵
 
 
 
    if(w <= h)
 
        gluOrtho2D(-1.0,1.5,-1.5,1.5*(GLfloat)h/(GLfloat)w);
 
//定义二维正视投影矩阵
 
    else
 
        gluOrtho2D(-1.0,1.5*(GLfloat)w/(GLfloat)h,-1.5,1.5);
 
    glMatrixMode(GL_MODELVIEW);
 
//指明当前矩阵为GL_MODELVIEW
 
}
 
 
int main(int argc, char* argv[]){
 
// 初始化
 
    glutInit(&argc,argv);
 
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
 
    glutInitWindowSize(400,400);
 
    glutInitWindowPosition(200,200);
 
 
//创建窗口
 
    glutCreateWindow("Triangle");
 
 
//绘制与显示
 
    background();
 
    glutReshapeFunc(myReshape);
 
    glutDisplayFunc(myDisplay);
 
    glutMainLoop();
 
    return(0);
 
}
 
 
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow){
    char* argv[20] = {"a.bmp"};
 
    main(1,argv);
    return 0;
}

  

vc如何编译链接opengl库,布布扣,bubuko.com

vc如何编译链接opengl库

原文:http://www.cnblogs.com/yejinru/p/3588454.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!