SDL具体安装

这里用的是:VC2008 + SDL-devel-1.2.15-VC ;
 
1:配置头文件路径和库文件路径;
 
 
 
 
 
 
 
2:编写程序,包含头文件,和库文件:例子如下:
 

#include <SDL.h>
#pragma comment(lib,"sdl.lib")
#pragma comment(lib,"SDLmain.lib")

void CtestsdlDlg::OnBnClickektestsdl()
{
 // TODO: 在此添加控件通知处理程序代码
 if((SDL_Init(SDL_INIT_EVERYTHING)==-1))
 {
  printf("Could not initialize SDL: %s.\n", SDL_GetError());
  return  ;

 }
 printf("hello ,the SDL world\n");

 /* Shutdown all subsystems */
 SDL_Quit();

}

 

3:这里的配置我没有做任何特殊处理,但是其他的一些文章还有其它的配置修改,

我查看了一下配置,原来:VC2008的mfc这些默认配置就已经符合要求了;

参考一下转载的其它文章。

 
 //转一篇专业文章:

Setting up SDL in Visual Studio.NET 2005/2008 Express

Last Updated 2/18/12
Before you start, make sure you have the latest versions of Visual C++ 2005 express, and the Visual Studio service pack. If you don't, SDL will not work with Visual C++ 2005 express. I have a mini tutorial to properly set up VC++ here.
1)First thing you need to do is download SDL headers and binaries.
You will find them on the SDL website, specifically on this page.

Scroll Down to the Development Libraries section and download the Windows development library

Open the zip and there should be a folder inside of it.
Copy that folder to where ever you want. In these tutorials I'm putting the folder in C:\.

2)Start up Visual Studio and go to Tools -> Options:

3)Next go to the "VC++ Directories" under "Projects and Solutions". Set "Show Directories For:" to "Include files". Click on the folder icon.

Add the include directory from the SDL folder you extracted.


4)Set "Show Directories For:" to "Library files" and find the lib directory from the SDL folder you extracted.



For certain versions of SDL, there will be a x86 folder and a x64 folder inside of the lib folder from the archive. The x86 folder contains the 32bit *.lib files and the x64 bit folder contains the 64bit versions of the library files. If you're compiling a 32bit program, set the new library directory to the x86 folder and if you're compiling a 64bit version set the new library directory to the x64 folder. By default Visual Studio compiles in 32bit so if you're not sure how you're compiling, try the 32bit libraries first. What matters here is not whether you have 32/64bit windows, but what type of program you're compiling.

If you don't see a x86 or x64 folder inside of the lib directory from the archive, just set the lib folder from the archive as the new library directory.

5)Now take the SDL.dll from the archive (it should be inside the lib subfolder) and extract it. You're going to put this in the same directory as your project/exe when you compile it.

Alternatively, you can copy SDL.dll to C:\WINDOWS\SYSTEM32 so your SDL app will find SDL.dll even if it's not in the same directory. If you're using a 64bit version of Windows, you'll want to put the dll in C:\Windows\SysWOW64.

The problem with this method is if you have multiple SDL apps that use different versions of SDL, you'll have version conflicts. If you have SDL 1.2.8 in SYSTEM32 when the app uses 1.2.13 you're going to run into problems. Generally you want to have your SDL.dll in the same directory as your executable developing and you'll always want to have SDL.dll in the same directory as the exe when distributing your app.

6)Now start a new win32 console project:
and click ok.

7)Go to application settings and make sure it's an empty project:
and click ok.

8)Then add a new source file to the project:

9)Now paste the following code into your new source file:
#include "SDL.h"int main( int argc, char* args[] ){    //Start SDL    SDL_Init( SDL_INIT_EVERYTHING );        //Quit SDL    SDL_Quit();        return 0;    }
and save the source file.

10)Next go to project settings.

11)In the C/C++ menu under general, set "Detect 64-bit Portability Issues" to "No".

12)In the C/C++ menu under Code Generation, set "Runtime Library" to multi-threaded dll.

13)In the Linker menu under Input, paste:
SDL.lib SDLmain.lib
in the additional dependencies field.

13)In the System menu, set the subsystem to windows:

Now Build. Make sure SDL.dll is in the same directory as the project/executable. If there are no errors, you're finished. Otherwise go back and make sure you didn't skip a step.
The tutorials use #include "SDL/SDL.h" to include their header files. Simply change it to #include "SDL.h" to make it work with Visual Studio.

Also, In the archive you just downloaded there's a subfolder called "docs". It contains the SDL documentation.

I highly recommend that you extract them somewhere and keep it for reference.
 
 
 
 
 
 
 
 
 
 
 
 
 
//下面转一篇以前的VC6l配置文章:
 
 
 
SDL 编程基本知识 (2010-03-15 22:57)


官方的编程简要教程
非常不错的SDL教程。
一.Window下SDL环境安装
-----------------------------------------------------------------
在Windows 下可以用多种开发环境来安装。具体方法参见
但一般我比较习惯于使用VC++6.0来开发SDL程序,以下介绍在VC++安装和使用库.
首先下载编译好的SDL开发库.(当然你可以自己行编译库,一般不推荐)
1.下载后解压到指定目录,假设是 e:\huisen\SDL下, 把解压的头文件路径include拷贝一份改名为SDL(理由后面解释)
2.把lib/SDL.dll 拷贝到 windows\system32 ,以便程序运行能找到它运行。
配置VC++ 6.0。
在程序中使用SDL库,有两种模式,一种是在每个项目里加上SDL库的路径,另外一种更为简单好用的办法,是把SDL设为所有项目共享的库。方法在主菜单 tools-->options 选择directories页标签。
首先是头文件目当设为SDL库目录下的include目录,这样程序中直接可以使用头文件,在这里有一个细节,
一般SDL有头文件直接在include下面,但是LINUX版或一般的SDL程序是引用 #include <SDL/SDL.h>
这里把include 设为引用目录,会将成头文件找不到。所以建议把include目录拷贝改成SDL,方便移植的程序可以找到头文件.将SDL目录本身设为include如下设置
设SDL的lib路径为整个环境的库路径
测试SDL游戏
我们用一个简单的DEMO来演示整个SDL环境使用
1.在VC++ 6.0中建立一个console项目,把hello.c加和到项目中。
2.在项目中加入对SDL的库的链接。(SDL.lib和SDLmain.lib) 如果是调试版,要忽略链接msvcrt.lib
3.要求采用DLL多线程库来作运行库。(这是SDL FAQ的要求,否则有链接错误)
   在项目选项,c/C++-->Code Generation-->Using Runtime library选择
    Debug MultiThread DLL(DEBUG版)或者 MultiThread DLL(Release版)
4.删除编译选项中的/GZ (编译器堆栈检查功能).这个主要是为了去掉如下链接错误
   error LNK2001: unresolved external symbol __chkesp
  (参见上图)
运行测试程序,会有如下效果.
注意后面有一个控制台出现,所有printf将输出到终端上来。如果不需要显示控制台。
可以把链接选项里的 /subsystem:console 改为 /subsystem:windows 即可
二.Linux的SDL开发环境安装
-----------------------------------------------------------------
  Linux 首先需要安装SDL库和SDL开发库。安装方式有两种,一种是编译后安装(这个方法出问题可能性最小,建议用这个方法)
  另外一种是用rpm包来安装库和开发包。
  第一种方法编译安装首先下载
简单的解压缩
      tar xvzf SDL-1.2.14.tar.gz
    然后
      ./configure
       make
       make install.
  它将安装库到 /usr/local/lib ,头文件在/usr/local/include当中。
  测试hello程序
     gcc -o hello hello.c -lSDL  #编译语句
    执行程序 export LD_LIBRARY_PATH=/usr/local/lib;./hello
如果正确无误将会显示如下界面
  
三.SDL编程基本流程.
----------------------------------------------------------------
   SDL开发使用相关数据结构,必须在源码中使用 #include <SDL/SDL.h>
   在Linux链接时,必须要链接libSDL.so库。 即在gcc语句加入 -lSDL 选项.
   Windows下在VC界面的项目选项的链接库,加入 SDL.lib链接语句。
   SDL由八个子系统组成——音频、CDROM、事件处理、文件I/O、游戏杆、线程、记时器和视频,
在使用SDL库时,在程序开源要调用
   SDL_Init()来初始化,它有如下定义:
    intSDL_Init(Uint32flags);
    其中flags指明是哪一个子系统在初始化装入。一般用 SDL_INIT_EVERYTHING,表示所有模块装入.
实始化成功返回为0,失败返回-1;
如想初始化特定模块,可用特殊选项。如下列语句用于实始化视频与定时器模块
    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
   当SDL程序即出时,须调用SDL_Quit();来做一些清除工作。
   基本框架代码
   

#include<SDL/SDL.h>

int main()
{ 

   if((SDL_Init(SDL_INIT_EVERYTHING)==-1)){
   printf("Could not initialize SDL: %s.\n", SDL_GetError());
   return -1;
   }

         printf("hello ,the SDL world\n");
  
   /* Shutdown all subsystems */
   SDL_Quit();

}


文件:hello_sdl.zip
大小:9KB
下载:下载

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

chinabinlang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值