C++ Visual Studio 2013和OpenGL

C++ Visual Studio 2013和OpenGL,c++,opengl,visual-studio-2013,C++,Opengl,Visual Studio 2013,我最近从学校买了一台新笔记本电脑,并得到了一个新版本的VS。我在设置我的库时遇到了一点麻烦。 我创建了一个基本的SDL_窗口,以及一个SDL_上下文 我可以包含我的库并运行程序,但我不能调用像glClearColor或glGetStringGL\u版本这样的函数。我得到了一个相当严重的警告和一个我以前从未见过的错误,我猜它与2013年版本有关 我尝试忽略所有特定的默认库,并尝试更改programtype多线程DLL,即4。 我已经确保所有的dll文件都在我的系统文件夹中 让我好奇的是,glewI

我最近从学校买了一台新笔记本电脑,并得到了一个新版本的VS。我在设置我的库时遇到了一点麻烦。 我创建了一个基本的SDL_窗口,以及一个SDL_上下文

我可以包含我的库并运行程序,但我不能调用像glClearColor或glGetStringGL\u版本这样的函数。我得到了一个相当严重的警告和一个我以前从未见过的错误,我猜它与2013年版本有关

我尝试忽略所有特定的默认库,并尝试更改programtype多线程DLL,即4。 我已经确保所有的dll文件都在我的系统文件夹中

让我好奇的是,glewInit可以工作,但glClearColor不能工作等等

输出:

1> msvcrdt.libcinitexe.obj:警告LNK4098:defaultlib'msvcrt.lib' 与其他LIB的使用发生冲突;使用/NODEFAULTLIB:library

1> Window.obj:错误LNK2019:未解析的外部符号 __小鬼__glClearColor@16在函数public:void\uu thiscall Window::initOpenGLvoid中引用?initOpenGL@Window@@QAEXZ

1> C:\Users\Aleksander\documents\visual studio 2013\Projects\OpenGL Test\Debug\OpenGL Test.exe:致命错误LNK1120:1未解决 外部

标题:

#pragma once
#include <SDL.h>            //Tested OK
#include <SDL_image.h>      //Tested OK
#include <SDL_mixer.h>      //Tested OK
#include <SDL_net.h>        //Tested OK
#include <OpenGL\glew.h>        //?
#include <freeglut\freeglut.h>  //?
#include <gl\GL.h>              //?
#include <glm\glm.hpp>      //Tested OK
#include <iostream>         //Standard OK
#include <Box2D\Box2D.h>    //Tested OK
using namespace std;


class Window {
    SDL_Window *window;
    SDL_GLContext context;
    bool quit;

public:
    Window();
    ~Window();

    void initSDL();
    void initOpenGL();
    void run();
};

您是否尝试过它所建议的/NODEFAULTLIB构建选项?您是否链接到opengl32.lib?是的,我尝试过链接器>输入>忽略所有默认库>是/NODEFAULTLIB附加依赖项:我可能会尝试添加它。glew32.lib glew32s.lib glew32mx.lib glew32mxs.lib谢谢n0rd,我将opengl32.lib添加到我的依赖项中,它工作了。令人惊讶的是,忽视事情是多么容易=/
#include "Window.h"


Window::Window() {
    printf("Starting window...\n");

    //Initialize window
    quit = false;
    initSDL();
    initOpenGL();

    //Run window
    run();
}

Window::~Window() {
    printf("Closing window...\n");

    //Clear window memory
    SDL_GL_DeleteContext(context);
    SDL_DestroyWindow(window);

    //Close window library
    SDL_Quit();
}

void Window::initSDL() {
    if (SDL_Init(SDL_INIT_EVERYTHING) == -1) {
        quit = true;
        printf("Unable to initialize SDL!\n");
    }
    else {
        //Create window
        const char *title = "OpenGL Test";
        int pos = SDL_WINDOWPOS_CENTERED;
        int w = 800;
        int h = 600;
        Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
        window = SDL_CreateWindow(title, pos, pos, w, h, flags);

        //Create OpenGL context
        SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
        SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
        SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
        SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
        SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
        context = SDL_GL_CreateContext(window);
    }
}

void Window::initOpenGL() {
    GLenum init = glewInit();
    if (init != GLEW_OK) {
        quit = true;
        printf("Unable to initialize OpenGL!\n");
        printf("Error: %s!\n", glewGetErrorString(init));
    }
    else {
        //printf("Vendor: %s\n", glGetString(GL_VENDOR));
        //printf("Version: %s\n", glGetString(GL_VERSION));
        //printf("Renderer: %s\n", glGetString(GL_RENDERER));
    }
}

void Window::run() {
    printf("Window started running!\n");

    SDL_Event event;

    while (!quit) {
        SDL_GL_SwapWindow(window);

        while (SDL_PollEvent(&event)) {
            if (event.type == SDL_QUIT) {
                quit = true;
            }
        }
    }
}