2008年11月29日星期六

SDL库在Qt .pro中设定

在.pro 里加上以下的Script:
INCLUDEPATH = "C:\SDL-devel-1.2.13-mingw32\SDL-1.2.13\include\SDL"
win32:LIBS += -L"C:\MinGW\lib" -lmingw32 \
-L"C:\SDL-devel-1.2.13-mingw32\SDL-1.2.13\lib" -lSDLmain -lSDL
注意1: INCLUDEPATH的双引号可加可不加,win32:LIBS的双引号最好加上

2:win32:LIBS加入的顺序是很重要的

3:用 \ 和 / 效果是一样的对于连接

4:不同的文档用 \ 相隔

5:当写-L时,写-lSDLmain而不是libSDLmain.a 等等,注意写的规范性。

举一个实例:让使用Qt的项目(使用MinGW gcc)可以编译SDL_image
1.在.pro中加入
INCLUDEPATH = C:\SDL_image-1.2.7\include
win32:LIBS += C:\SDL_image-1.2.7\lib\SDL_image.lib
2.将C:\SDL_image-1.2.7\lib中的.dll文件拷到C:\WINDOWS\system32里去
3.在所需的C++文件中加入头文件:#include "SDL_image.h"



1 条评论:

KOCHI奇異想法 说...

您好,不知道再这里发问适不适合,但我找不到您的e-mail,所以还是选择在此直接问您。
参考了您的帖子之后,我把.pro檔加入以下参数
INCLUDEPATH = "C:\SDL-devel-1.2.13-mingw32\SDL-1.2.13\include\SDL"
win32:LIBS += C:\SDL-devel-1.2.13-mingw32\SDL-1.2.13\lib\libSDL.dll.a
win32:LIBS += C:\SDL-devel-1.2.13-mingw32\SDL-1.2.13\lib\libSDL.la
win32:LIBS += C:\SDL-devel-1.2.13-mingw32\SDL-1.2.13\lib\libSDLmain.a
并把\bin\SDL.dll文件放入system数据夹里面,但还是会出现以下错误讯息,
C:\SDL-devel-1.2.13-mingw32\SDL-1.2.13\lib\libSDL.la: file not recognized: File format not recognized
collect2: ld returned 1 exit status
mingw32-make.exe[1]: *** [debug\test_sdl.exe] Error 1
mingw32-make.exe: *** [debug] Error 2
Exited with code 2.
Error while building project test_sdl
When executing build step 'Make'

LIBS这边因为我搜寻不到*lib的檔,所以我将lib数据夹的三个文件名称写在后面,但看了错误讯息之后我删除了win32:LIBS += C:\SDL-devel-1.2.13-mingw32\SDL-1.2.13\lib\libSDL.la
结果错误讯息变成
c:\Qt\2009.02\qt\lib/libqtmaind.a(qtmain_win.o)(.text+0x309): In function `WinMain':
C:/qt-greenhouse/Trolltech/Code_less_create_more/Trolltech/Code_less_create_more/Troll/4.5.0/qt/src/winmain/qtmain_win.cpp:136: undefined reference to `qMain(int, char**)'
collect2: ld returned 1 exit status
mingw32-make.exe[1]: *** [debug\test_sdl.exe] Error 1
mingw32-make.exe: *** [debug] Error 2
Exited with code 2.
Error while building project test_sdl
When executing build step 'Make'

不知道是否能给我个建议去除错??感激您!!
如不嫌麻烦的话,是否可以寄到信箱,u9211048@ccms.nkfust.edu.tw

BY 黄科期