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`

转载地址: https://blog.csdn.net/zhouzhenhe2008/article/details/54428761

阅读更多

没有更多推荐了,返回首页