gpt4 book ai didi

c++ - Visual Studio 2012 C++ OpenGL GLFW 链接器错误

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:29:54 26 4
gpt4 key购买 nike

<分区>

我正在 Visual Studio 2010 Express 上使用 OpenGL 在 C++ 中制作一个二维横向卷轴器。我正在尝试编译我的代码,它可以正确构建,但是我在 main() 函数中初始化的 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>------ Build started: Project: Prized Fighter, Configuration: Debug Win32 ------ 1>main.obj : error LNK2019: unresolved external symbol _glfwSwapBuffers referenced in >function _WinMain@8

1>main.obj : error LNK2019: unresolved external symbol _glfwSetWindowTitle referenced in >function _WinMain@8

1>main.obj : error LNK2019: unresolved external symbol _glfwOpenWindow referenced in >function _WinMain@8

1>main.obj : error LNK2019: unresolved external symbol _glfwInit referenced in function >_WinMain@8

1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol WinMain@16 >referenced in function __tmainCRTStartup

1>c:\users\brennan\documents\visual studio 2010\Projects\Prized Fighter\Debug\Prized >Fighter.exe : fatal error LNK1120: 5 unresolved externals ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

链接过程中出了什么问题 - 代码中是否有错误?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com