我在C++中使用Visual Studio 2010 Express上的OpenGL制作了2d侧滚动器。我试图编译我的代码,并且它的构建正确,但是我在main()函数中初始化GLFW函数时出现链接器错误。这里是我的代码: Visual Studio 2012 C++ OpenGL GLFW链接器错误
#include <iostream>
#include <ctime>
#include <GL\glfw.h>
#include "Player.h"
void render();
void update();
Player Player1;
//Cross platform sleep implementation
void _sleep(double ms)
{
double st = clock();
if(ms <= 0)
ms = 10;
while(clock() < (ms + st));
}
int main(int argc, char** argv)
{
std::cout <<"Loading Prized Fighter"<< std::endl;
glfwInit(); //Initialize GLFW
//Create GLFW window
if(glfwOpenWindow(800, 600, 5, 6, 5, 0, 8, 0, GLFW_WINDOW) != GL_TRUE)
std::cout << "Error creating window!" << std::endl;
//Set window title
glfwSetWindowTitle("Prized Fighter");
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//Start main game loop
//This calls the functions which update objects and render them to the screen
while(true)
{
update();
render();
glfwSwapBuffers(); //Switch buffers (double rendering)
_sleep(10.0); //Let a bit of CPU time for other processes
}
return 0;
}
/*
- Render function -
Used to draw objects to the screen
*/
void render()
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //Color to clear the screen
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//TODO: Draw stuff here
Player1.draw();
}
/*
- Update function -
Updates objects; states, locations, etc
*/
void update()
{
//TODO: Update objects here
Player1.update();
}
当我编译,我得到以下错误:
1> ------构建开始:项目:珍贵的战斗机,配置:调试的Win32 - ----- 1> main.obj:错误LNK2019:错误LNK2019:中引用>功能_WinMain @ 8
1> main.obj解析外部符号_glfwSwapBuffers解析外部符号_glfwSetWindowTitle引用在>功能_WinMain @ 8
1> main.obj:错误LNK2019:解析外部符号_glfwOpenWindow引用在>功能_WinMain @ 8
1> main.obj:错误LNK2019:解析外部符号_glfwInit在函数引用> _WinMain @ 8
1> MSVCRTD.LIB(crtexew.obj):错误LNK2019:解析外部符号的WinMain @ 16>在函数引用_ _tmainCRTStartup
1> C:\用户\布伦南\文件\视觉工作室2010 \项目\ Priged Fighter \ Debug \ Prized> Fighter.exe:致命错误LNK1120:5个未解析的外部设备 === =======构建:0成功,1失败,0最新,0跳过==========
链接过程中出现了什么问题 - 是代码中的错误?
你链接到适当的库吗? –