微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决无法在 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 举报,一经查实,本站将立刻删除。