我是靠谱客的博主 快乐小蝴蝶,最近开发中收集的这篇文章主要介绍ubuntu上安装SDL2,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述


执行这两个命令就可以了
sudo apt-get install libsdl2-2.0

sudo apt-get install libsdl2-dev

引用SDL2库编译自己的程序
gcc -o myprogram myprogram.c `sdl2-config --cflags --libs`


以下摘自官网

https://wiki.libsdl.org/Installation

Supported platforms

Linux/Unix

Several other platforms will be built "the Unix way," so we'll describe this platform first.

SDL supports most popular flavors of Unix: Linux 2.6+, the various BSDs (FreeBSD, NetBSD, OpenBSD), Solaris, and other things like them.

First! Do you need to compile SDL yourself? It's possible your distribution's package manager already did it for you!

Debian-based systems (including Ubuntu) can simply do "sudo apt-get install libsdl2-2.0" to get the library installed system-wide, and all sorts of other useful dependencies, too. "sudo apt-get install libsdl2-dev" will install everything necessary to build programs that use SDL. Please see docs/README-linux.md for a more complete discussion of packages involved.

Red Hat-based systems (including Fedora) can simply do "sudo yum install SDL2" to get the library installed system-wide, or "sudo yum install SDL2-devel" to get headers and other build requirements ready for compiling your own SDL programs.

Gentoo users can "sudo emerge libsdl2" to get everything they need.

If you're compiling SDL yourself, here's what we refer to as "the Unix way" of building:


If you're compiling SDL yourself, here's what we refer to as "the Unix way" of building:

  • Get a copy of the source code, either from Mercurial or an official tarball or whatever.
  • Make a separate build directory (SDL will refuse to build in the base of the source tree).
  • Run the configure script to set things up.
  • Run "make" to compile SDL.
  • Run "make install" to install your new SDL build on the system.

This looks something like this:

hg clone https://hg.libsdl.org/SDL SDL
cd SDL
mkdir build
cd build
../configure
make
sudo make install

The last command says "sudo" so we can write it to /usr/local (by default). You can change this to a different location with the --prefix option to the configure script. In fact, there are a LOT of good options you can use with configure! Be sure to check out its --help option for details. SDL tries to do the right thing by default, though, so you can usually get away with no options at all. "make" could be "make -j4" or whatever if you have more than one CPU; SDL can safely be built in parallel across all the CPU cores you have available to you. A good rule of thumb for Linux is the number of cores plus two, so you use all the processing resources possible, and if a process or two is competing for the disk, those two extra jobs might be able to put the otherwise-idle CPU cores to work in the meantime (so on a four-core system? Try "make -j6".)

An (experimental!) alternative to the configure script is the CMake project file. It works on similar principles to the configure script, but you might find that you enjoy it more, if this is the sort of thing you generally enjoy in the first place. Driving that is left as an exercise for the reader.

Once you have the library installed, you can use the sdl2-config program to help you compile your own code:

  • gcc -o myprogram myprogram.c `sdl2-config --cflags --libs`


最后

以上就是快乐小蝴蝶为你收集整理的ubuntu上安装SDL2的全部内容,希望文章能够帮你解决ubuntu上安装SDL2所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(75)

评论列表共有 0 条评论

立即
投稿
返回
顶部