前景提要
HDC调试需求开发(15万预算),能者速来!>>>
最近在学习SDL的开发,想用平时熟悉的IDE:Code::Blocks来编写SDL程序。但是我按照网上的方法试了一下,都配置不成功.然后编译不了:
我用的是Code::Blocks 12.11.用的SDL2是官网下载的 SDL2-d SDL2-devel-2.0.1-mingw.tar.gz ( MinGW 32/64-bit)开发包版本。
在Code::Blocks下的配置是按照:
建立一个空的工程(Empty Project) 在构建选项下的Search directiories下的编译器路径中添加:
D:\SDL2-2.0.1_64-w64-mingw32\include\SDL2 在链接器路径中添加:
D:\SDL2-2.0.1_64-w64-mingw32\lib
上图:
然后在Linker Settings下添加其他编译器选项:
-lmingw32 -lSDL2 -lSDL2main -lSDL2.dll -luser32 -lgdi32 -lwinmm -ldxguid -mwindows
然后确定,加入一个最简单的SDL2程序:(main.cpp):
#include <SDL.h> #include <stdio.h> const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; int main( int argc, char* args[] ) { SDL_Window* window = NULL; SDL_Surface* screenSurface = NULL; if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() ); } else { window = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN ); if( window == NULL ) { printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() ); } else { screenSurface = SDL_GetWindowSurface( window ); SDL_FillRect( screenSurface, NULL, SDL_MapRGB( screenSurface->format, 0xFF, 0xFF, 0xFF ) ); SDL_UpdateWindowSurface( window ); SDL_Delay( 2000 ); } } SDL_DestroyWindow( window ); SDL_Quit(); return 0; }
然后,编译.提示以下错误:
-------------- Build: Debug in TestSDL2 (compiler: GNU GCC Compiler)--------------- mingw32-g++.exe -Wall -g -ID:\SDL2-2.0.1_64-w64-mingw32\include\SDL2 -c D:\CWork\TestSDL2\main.cpp -o obj\Debug\main.o mingw32-g++.exe -LD:\SDL2-2.0.1_64-w64-mingw32\lib -o bin\Debug\TestSDL2.exe obj\Debug\main.o -lmingw32 -lSDL2 -lSDL2main -lSDL2.dll -luser32 -lgdi32 -lwinmm -ldxguid -mwindows obj\Debug\main.o: In function `SDL_main': D:/CWork/TestSDL2/main.cpp:12: undefined reference to `SDL_Init' D:/CWork/TestSDL2/main.cpp:14: undefined reference to `SDL_GetError' D:/CWork/TestSDL2/main.cpp:18: undefined reference to `SDL_CreateWindow' D:/CWork/TestSDL2/main.cpp:21: undefined reference to `SDL_GetError' D:/CWork/TestSDL2/main.cpp:25: undefined reference to `SDL_GetWindowSurface' D:/CWork/TestSDL2/main.cpp:26: undefined reference to `SDL_MapRGB' D:/CWork/TestSDL2/main.cpp:26: undefined reference to `SDL_FillRect' D:/CWork/TestSDL2/main.cpp:27: undefined reference to `SDL_UpdateWindowSurface' D:/CWork/TestSDL2/main.cpp:28: undefined reference to `SDL_Delay' D:/CWork/TestSDL2/main.cpp:31: undefined reference to `SDL_DestroyWindow' D:/CWork/TestSDL2/main.cpp:32: undefined reference to `SDL_Quit' c:/program files/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/../../../libmingw32.a(main.o):main.c:(.text.startup+0xa7): undefined reference to `WinMain@16' collect2.exe: error: ld returned 1 exit status 过程结束,其状态为 1 (0 分钟, 2 秒) 12 errors, 0 warnings (0 minutes, 2 seconds) 求大神帮我看看,我哪儿错了。网上也找不到解决的方法。配置到底出了什么问题呀。