用代码块在C++中编译Glew和SDL
Compiling Glew and SDL in C++ with Code::Blocks
在过去的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:ProgramsCodeBlocksglew-1.10.0include
E:ProgramsCodeBlocksSDL-1.2.15include
链接器:
E:ProgramsCodeBlocksglew-1.10.0libReleasex64
E:ProgramsCodeBlocksSDL-1.2.15lib
最后在链接器设置中,我有
链接库:
E:ProgramsCodeBlocksglew-1.10.0libReleasex64glew32s.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编译器。