无法在 Visual Studio 2019 中运行 GLUT/GLFW/GLEW 项目

问题描述

我正在尝试通过使用 Visual Studio 使用 C++ 进行编码来学习 openGL。我已经在我的项目中为 GLUT、GLEW 和 GLFW 设置了依赖项。我试图运行的代码相当简单:

#include "main.h"
#include "stdio.h"
#include "stdlib.h"

#include "GL/glew.h"
#include "GL/wglew.h"


#include "GL/glut.h"
#include "GLFW/glfw3.h"

#include "glm/glm.hpp"



int main(int argc,char** argv) {

    
    glewExperimental = true;

    if (!glfwInit()) {
        fprintf(stderr,"Failed to intiialize GLFW\n");
        return -1;
    }

    glfwWindowHint(GLFW_SAMPLES,4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR,3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR,3);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT,GL_TRUE); // To make MacOS happy; should not be needed
    glfwWindowHint(GLFW_OPENGL_PROFILE,GLFW_OPENGL_CORE_PROFILE); // We don't want the old OpenGL 

    //Open a window,create the openGL context

    GLFWwindow* window;

    window = glfwCreateWindow(1024,768,"My funky window!",NULL,NULL);

    if (window == NULL) {
        fprintf(stderr,"Failed to open GLFW window.\n");
        glfwTerminate();
        return -1;
    }
    glfwMakeContextCurrent(window); //initialize GLEW
    glewExperimental = true; //needed in core profile

    if (glewInit() != GLEW_OK) {
        fprintf(stderr,"Failed to initialize GLEW.\n");
        return -1;
    }


    return 0;
}

但是,当我在调试中运行此代码时,我收到一个消息框,提示存在构建错误并且它没有创建 .exe。这是打印到控制台的内容:

Build started...
1>------ Build started: Project: testProject,Configuration: Debug Win32 ------
1>main.obj : error LNK2019: unresolved external symbol __imp__glewInit@0 referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _glfwInit referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _glfwTerminate referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _glfwWindowHint referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _glfwCreateWindow referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _glfwMakeContextCurrent referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol __imp__glewExperimental referenced in function _main
1>C:\Users\iancr\Desktop\OpenGLRoot\testProject\\..\External Resources\GLFW\lib-vc2019\glfw3.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'x86'
1>C:\Users\iancr\Desktop\OpenGLRoot\testProject\Debug\testProject.exe : fatal error LNK1120: 7 unresolved externals
1>Done building project "testProject.vcxproj" -- FAILED.
========== Build: 0 succeeded,1 failed,0 up-to-date,0 skipped ==========

我不知道为什么它不能识别这些函数或者 64 与 x86 的东西是关于什么的。我对 C++ 还很陌生,所以我想这是我忽略的一些基本知识。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...