SDL_GetDefaultAudioInfo is completely missing

I am trying to set up basic audio functionality. It seems to me that the first step is to use SDL_GetDefaultAudioInfo to grab the SDL_AudioSpec for the default device so I can use the other audio-related functions. When I try to call SDL_GetDefaultAudioInfo, however, I get an error

‘SDL_GetDefaultAudioInfo’ was not declared in this scope;

Other names from SDL_audio.h appear to be recognized without any issue. I decided to check SDL_audio.h myself, and there isn’t any mention of SDL_GetDefaultAudioInfo in the file at all! I have no clue how this happened. I installed SDL2 for Linux according to SDL2/Installation - SDL2 Wiki, using apt. I never had any problems with missing functions in SDL.h, either.

Have I made a mistake in the installation? Is this function supposed to be missing?

What version of SDL 2 is installed? The docs say that SDL_GetDefaultAudioInfo() was only added in SDL 2.24.0, and a lot of Linux distros ship old versions of SDL 2.

2 Likes

Yes, looking at it again, it seems like I have version 2.0.20. I must have made a mistake in that I checked the release date of 2.24.0 and assumed because it released before I installed my OS, I would have it.

$ apt show libsdl2-2.0-0
Package: libsdl2-2.0-0
Version: 2.0.20+dfsg-2ubuntu1.22.04.1

So if I want to use a more recent version of SDL2, I would need to manually install it? I’ve only done a quick search, but it looks like my available package sources don’t have any recent versions.

I think the naming convention for libsdl2-2.0-0 also confused me a lot. I always assumed that the -2.0-0 suffix was some kind of strange version numbering pattern, but it doesn’t seem like that’s correct?

What’s the latest version of libsdl2 available (leaving off all the 2.0-0 whatever)?

Looks like the most recent available version via apt is 2.0.20. That’s a bit disappointing.

$ apt policy libsdl2-2.0-0
libsdl2-2.0-0:
  Installed: 2.0.20+dfsg-2ubuntu1.22.04.1
  Candidate: 2.0.20+dfsg-2ubuntu1.22.04.1
  Version table:
 *** 2.0.20+dfsg-2ubuntu1.22.04.1 500
        500 http://apt.pop-os.org/ubuntu jammy-updates/main amd64 Packages
        100 /var/lib/dpkg/status
     2.0.20+dfsg-2build1 500
        500 http://apt.pop-os.org/ubuntu jammy/main amd64 Packages

I realize I should have also specified this earlier, but my operating system is Pop_OS 22.04

What does it say if you just check “libsdl2”? Leave the “-2.0-0” off.

(this is because the versioning scheme changed towards the end of SDL2, where it jumped from SDL 2.0.22 to SDL 2.24.0; if you’re specifically requesting SDL 2.0 then you’ll never get anything past SDL 2.0.22)

$ apt search libsdl2
    Sorting... Done
    Full Text Search... Done
    libsdl2-2.0-0/jammy-updates,now 2.0.20+dfsg-2ubuntu1.22.04.1 amd64 [installed]
      Simple DirectMedia Layer
    
    libsdl2-dev/jammy-updates,now 2.0.20+dfsg-2ubuntu1.22.04.1 amd64 [installed]
      Simple DirectMedia Layer development files
    
    libsdl2-doc/jammy-updates,jammy-updates 2.0.20+dfsg-2ubuntu1.22.04.1 all
      Reference manual for libsdl2

Looks like the only version of SDL2 available on my package sources is just 2.0.22. I think I’ll just need to install it manually, which is kind of a pain but it’s not horrible. I also get the feeling that there’s something incredibly obvious that I’m missing, but it really seems like this is just a restriction I need to put up with?

A lot of Linux distros just ship old SDL.

Is there a newer version of your distro?

Different Linux distributions make different tradeoffs. Debian based distros favour stability while for example Arch Linux favour cutting edge.

No, it looks like 22.04 is the latest version of Pop!_OS. It’s a shame that I don’t have SDL_GetDefaultAudioInfo, but if my currently installed SDL version is from before it exists, then presumably I can just skip it entirely?

@javinson

Hello,

What returns (in some terminal) the following command:

sdl2-config --version

If sdl2-config is not found, please install libsdl2-dev (or the -dev package linked to libsdl2 for your distribution)
HTH