![](/img/trans.png)
[英]Error : "SDL could not initialize! SDL_Error: dsp: No such audio device"
[英]failure to initialize SDL audio
當我調用 SDL_Init 傳入 SDL_AUDIO_INIT 時,function 返回失敗。
我調用了 SDL_GetError() 但似乎沒有任何消息。 我在初始化 VIDEO 時沒有遇到問題,只有音頻。 編譯時我沒有收到任何錯誤。 我已經在我的 makefile 中鏈接了 SDL 混音器庫。
這是一個最小的可重現示例代碼:
#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() );
}
else
{
printf("video and audio initialized");
}
return 0;
}
output:SDL AUDIO 無法初始化:SDL 錯誤:
(沒有錯誤消息)
這是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
COMPILER_FLAGS = -g -Wall
#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)
$(CC) $(OBJS) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o $(OBJ_NAME)
我正在使用 Ubuntu 20.04
安裝 libasound2-dev libpulse-dev
並重新編譯 SDL2
音頻驅動:disk dummy oss alsa(dynamic) pulse(dynamic) <--- OK
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.