我在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跳過==========
鏈接過程中出現了什麼問題 - 是代碼中的錯誤?
你鏈接到適當的庫嗎? –