C++ 将 SDL 库添加到我的程序中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14646208/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 18:33:13  来源:igfitidea点击:

Adding SDL library to my program

c++sdl

提问by Tomá? Zato - Reinstate Monica

there are a few questions on that already, but all askers are, lets say it, one level above me. All I know there are some download links hereand that I should probably download SDL-1.2.15-win32-x64.zip (64-bit Windows)to match my system and SDL-devel-1.2.15-mingw32.tar.gz (Mingw32)to match my compiler. Now what? The development archive contains some C++ project and I have no idea, what should I do with it. What files to include? What files to link in linker?

已经有几个问题了,但是所有提问者都比我高一个级别。我只知道有一些下载链接在这里和我应该下载SDL-1.2.15-win32-x64.zip(64位Windows) ,以配合我的系统和SDL-devel的-1.2.15-mingw32.tar.gz (Mingw32)匹配我的编译器。怎么办?开发档案包含一些 C++ 项目,我不知道该怎么办。要包含哪些文件?在链接器中链接哪些文件?

Edit:

编辑:

Info

信息

System: Windows 7x64
IDE: Code::Blocks Compiler: G++

系统:Windows 7x64
IDE:代码::块编译器:G++

回答by Tomá? Zato - Reinstate Monica

So the actual answer to my question is just the link to this manual for dummies: http://lazyfoo.net/SDL_tutorials/lesson01/index.php
Here anyone can choose his environment to get the help. I get no credits to this answer - @Ergo Proxy has posted it as comment to my question. But this is what I needed.

所以我的问题的实际答案只是这个傻瓜手册的链接:http: //lazyfoo.net/SDL_tutorials/lesson01/index.php
这里任何人都可以选择他的环境来获得帮助。我对这个答案没有任何评价 - @Ergo Proxy 已将其发布为对我的问题的评论。但这正是我所需要的。

回答by duDE

It seems to be a good begin: using SDL2 to create an application window. You need just to link the static sdl.lib (or sdl2.lib if you have the very last version of SDL). Try to compile and execute it.

这似乎是一个好的开始:使用 SDL2 创建一个应用程序窗口。您只需要链接静态 sdl.lib(或 sdl2.lib,如果您拥有最新版本的 SDL)。尝试编译并执行它。

#include <SDL2/SDL.h>
#include <iostream>

int main(int argc, char* argv[]){

  SDL_Init(SDL_INIT_VIDEO);   // Initialize SDL2

  SDL_Window *window;        // Declare a pointer to an SDL_Window

  // Create an application window with the following settings:
  window = SDL_CreateWindow( 
    "An SDL2 window",                  //    window title
    SDL_WINDOWPOS_UNDEFINED,           //    initial x position
    SDL_WINDOWPOS_UNDEFINED,           //    initial y position
    640,                               //    width, in pixels
    480,                               //    height, in pixels
    SDL_WINDOW_SHOWN|SDL_WINDOW_OPENGL //    flags - see below
  );

  // Check that the window was successfully made
  if(window==NULL){   
    // In the event that the window could not be made...
    std::cout << "Could not create window: " << SDL_GetError() << '\n';
    return 1;
  }

  // The window is open: enter program loop (see SDL_PollEvent)

  SDL_Delay(3000);  // Pause execution for 3000 milliseconds, for example

  // Close and destroy the window
  SDL_DestroyWindow(window); 

  // Clean up
  SDL_Quit(); 
  return 0;   

}

回答by akrami

I have installed SDL on visual studio. it's easy and you'd better use it because it doesn't need mingw. go to SDL website and download SDL-devel-1.2.15-vc.zip package. then extract it in your system. then open your visual studio, goto your project's properties in "VC directories" section you should set the SDL address. add SDL\lib to "lib directories" and SDL\include to "includes". after this, in project properties goto linker\input then add "SDL.lib" to it's first property. after all you can compile your codes with it.

我已经在 Visual Studio 上安装了 SDL。它很容易,你最好使用它,因为它不需要 mingw。转到 SDL 网站并下载 SDL-devel-1.2.15-vc.zip 包。然后在您的系统中提取它。然后打开你的visual studio,在“VC目录”部分转到你的项目属性,你应该设置SDL地址。将 SDL\lib 添加到“lib 目录”并将 SDL\include 添加到“包含”。在此之后,在项目属性中转到链接器\输入然后将“SDL.lib”添加到它的第一个属性。毕竟你可以用它编译你的代码。