• Uncategorized

About c++ : failure-to-initialize-SDL-audio

Question Detail

When i Call SDL_Init passing in SDL_AUDIO_INIT, the function returns a failure.

I called SDL_GetError() but there does not seem to be any message.
I am not having problems getting VIDEO to initialize, only audio. I don’t get any errors when compiling. I have linked the SDL mixer library in my makefile.

Here is a minimum reproducible example code:

#include <SDL2/SDL.h>
#include <stdio.h>
#include <string>

int main( int argc, char* args[] )

        //Initialize SDL
        if( SDL_Init( SDL_INIT_VIDEO  < 0))
                printf( "SDL VIDEO could not initialize! SDL Error: %s\n", SDL_GetError() );
        else if ( SDL_Init( SDL_INIT_AUDIO) < 0)
                printf( "SDL AUDIO could not initialize! SDL Error: %s\n", SDL_GetError() );
                printf("video and audio initialized");

        return 0;

output: SDL AUDIO could not initialize! SDL Error:

(there is no message for the error)

Here is the makefile

#OBJS specifies which files to compile as part of the project
OBJS = 21_sound_effects_and_music.cpp 

#CC specifies which compiler we're using
CC = g++

#COMPILER_FLAGS specifies the additional compilation options we're using
# -w suppresses all warnings

#LINKER_FLAGS specifies the libraries we're linking against
LINKER_FLAGS = -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer

#OBJ_NAME specifies the name of our exectuable
OBJ_NAME = sdl_program

#This is the target that compiles our executable
all : $(OBJS)

I am using Ubuntu 20.04

Question Answer

install libasound2-dev libpulse-dev

and recompyling SDL2

Audio drivers : disk dummy oss alsa(dynamic) pulse(dynamic) <— IS OK

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.