简体   繁体   中英

Linking errors in visual studio 2015

When trying to build project I got an error cannot open file "kernel32.lib", after some googling I added $(LibraryPath) on the end of Library directories.

在此处输入图片说明

By doing that I got rid of previous error, yet now I get a bunch of other ones:

在此处输入图片说明

And Here`s my code:

    //GLEW
#define GLEW_STATIC
#include <glew.h>
//GLFW
#include <glfw3.h>
#include <iostream>

int main()
{
    glfwInit();

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

    GLFWwindow* window = glfwCreateWindow(800, 600, "Learning OpenGL :)", nullptr, nullptr);

    if (window == nullptr)
    {
        std::cout << "Failed to create window\n";
        glfwTerminate();
        return -1;
    }

    glfwMakeContextCurrent(window);

    glewExperimental = GL_TRUE;

    if (glewInit() != GLEW_OK)
    {
        std::cout << "failed to initialize GLEW\n";
        return -1;
    }

    glViewport(0, 0, 800, 600);

    while (!glfwWindowShouldClose(window))
    {
        glfwPollEvents();
        glfwSwapBuffers(window);
    }

    glfwTerminate();
    return 0;
}

How can I fix all those linking errors and finally get my program running?

This works on my compiler, but I have all the stuff linked properly I guess. All I have is the same stuff you have, plus the linked libraries in the actual code. Try paste:

#pragma comment (lib, "glew32s.lib")
#pragma comment (lib, "glfw3.lib")
#pragma comment (lib, "OpenGL32.lib")

Before your main. Make sure glew.h is included BEFORE glfw headers. And make sure your library folders point to where these files are.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM