c++ - 使用 Code::Blocks 在 C++ 中编译 Glew 和 SDL

标签 c++ linker sdl glew

我花了最后 24 个工作小时来尝试编译它,使用了多个搜索和教程(有人说我需要动态链接它,而其他人说我需要静态链接),我无法让它工作。我对编译和链接比较陌生,因此不胜感激。

这是我的代码(正如你从我的评论中看出的那样,我昨晚为此编写代码非常累):

#define NO_SDL_GLEXT
#define GLEW_STATIC
#include "GL/glew.h"
#include "SDL/SDL.h"
#include "SDL/SDL_opengl.h"

int main (int argc, char* args[]){
    //Loads the SDL video module
    SDL_Init(SDL_INIT_VIDEO);

    //Creates the SDL Surface for OpenGL to draw to
    SDL_Surface* surface = SDL_SetVideoMode(800,600,32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_OPENGL );

    //Sets the caption...
    SDL_WM_SetCaption("OpenGL",0);

    glewExperimental = GL_TRUE;
    glewInit();

    //Main event loop, this is the BREAD AND BUTTER LADIES AND GENTLEMEN
    SDL_Event windowEvent;
    while (true){
        if (SDL_PollEvent(&windowEvent)){
            //If you close the appplication, causes it to actually stop running :D
            if (windowEvent.type == SDL_QUIT) break;

            //Close it with the ESC key! :D:D:D:D:D:D:D:D:D:
            if (windowEvent.type == SDL_KEYUP && windowEvent.key.keysym.sym == SDLK_ESCAPE) break;
        }
            //Literally the one extra line of code needed to do double buffering
        SDL_GL_SwapBuffers();
    }

    //I wish I knew what this ended...LOPE JK
    SDL_Quit();

    return 0;
}

在我的搜索目录中:

编译器:

E:\Programs\CodeBlocks\glew-1.10.0\include
E:\Programs\CodeBlocks\SDL-1.2.15\include

链接器:

E:\Programs\CodeBlocks\glew-1.10.0\lib\Release\x64
E:\Programs\CodeBlocks\SDL-1.2.15\lib

最后在我的链接器设置中

链接库:

E:\Programs\CodeBlocks\glew-1.10.0\lib\Release\x64\glew32s.lib

其他链接器选项:

-lmingw32 -lglew32s -DGLEW_STATIC -lSDLmain -lSDL

我目前得到的错误是:

In function 'SDL_main':
undefined reference to `glewExperimental'
undefined reference to `glewInit@0'

预先感谢您的所有帮助!

最佳答案

您收到链接器错误。看起来您正在使用 Mingw 编译器编译您的应用程序。但是,您确定您使用的 glew 库也是用/为 Mingw 构建的吗?如果您没有自己构建 glew 并下载了预构建的二进制文件,那么它很可能是使用 Visual Studio 构建的。请注意,像这样混合来自不同编译器的库并不简单。

看看这个: http://www.mingw.org/wiki/MSVC_and_MinGW_DLLs

P.S:除非反对专有软件的哲学原因阻止您这样做,否则您真的应该考虑使用 Visual Studio 编译器。 Visual Studio 编译器的快速版本是免费的(类似啤酒)。您可以在像 QtCreator 这样非常棒的 IDE 中使用 Visual Studio 编译器。

关于c++ - 使用 Code::Blocks 在 C++ 中编译 Glew 和 SDL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18197533/

相关文章:

c++ - 如何制作在每次输出操作后插入新行的流?

c++ - C++中虚函数的编译时静态类型检查

c++ - SDL 教程中的 LNK2019 错误,但仅在 Visual Studio 2010 中

opengl - SDL 三重缓冲

c++ - 如何在 for 循环中使用 random_engine 和 mt19937

python - 如何使 Swig 发出 C++ 父类(super class)

linker - 包括使用 dune 的子包(没有为模块提供实现,但模块位于 dune 文件中)

build-process - ld链接器问题: the --whole-archive option

c - OpenGL函数加载是如何工作的?

c++ - 以最通用的形式将 map 的第一个元素存储到 vector 中。最佳解决方案