![](/img/trans.png)
[英]How can I solve undefined reference errors with Conan and SDL2 on Ubuntu 16.10?
[英]Unable to set up SDL2 to run with audio (alsa) on linux ubuntu 20.04 using conan
根据我所做的,我要么得到
“没有这样的音频设备”
如果我将确定我的音频设备留给 SDL2 或者我得到
加载 libasound.a 失败:/home/aypahyo/.conan/data/libalsa/1.2.4///package / d48130e0dd76369b1338deb3b2372c5a649f9f2d / lib / libasound.a:无效的 ELF 头
当我设置SDL_AUDIODRIVER=alsa
。 (错误信息其实被截断了,我在最后加了一个r)。
这是一个显示错误的实现:
#include <SDL.h>
#include <iostream>
void SetupWant(SDL_AudioSpec * want);
void PrintError(std::string source);
void run()
{
//https://wiki.libsdl.org/FAQUsingSDL
putenv((char *)"SDL_AUDIODRIVER=alsa");
if(0 != SDL_Init(SDL_INIT_AUDIO)) PrintError("SDL_Init");
SDL_AudioSpec want, have;
SDL_AudioDeviceID dev;
SetupWant(&want);
dev = SDL_OpenAudioDevice(NULL, 0, &want, &have, SDL_AUDIO_ALLOW_FORMAT_CHANGE);
if (0 == dev) PrintError("SDL_OpenAudioDevice");
}
void SetupWant(SDL_AudioSpec * want)
{
SDL_memset(want, 0, sizeof(SDL_AudioSpec));
want->freq = 48000;
want->format = AUDIO_F32;
want->channels = 2;
want->samples = 4096;
}
void PrintError(std::string source)
{
std::cout << "error " << source << ": " << SDL_GetError() << "\n";
}
我使用 conan 在我的 CMake 项目中安装了依赖项。 这是柯南文件:
[requires]
sdl2/2.0.12@bincrafters/stable
sdl2_image/2.0.5@bincrafters/stable
sdl2_mixer/2.0.4@bincrafters/stable
flac/1.3.2@bincrafters/stable
glib/2.64.0@bincrafters/stable
boost/1.71.0@conan/stable
zlib/1.2.11@conan/stable
bzip2/1.0.8@conan/stable
gtest/1.10.0
glm/0.9.9.8
libmpg123/1.25.13@bincrafters/stable
libalsa/1.2.4
[generators]
cmake
依赖项sdl2/2.0.12@bincrafters/stable
没有源文件夹,但是我可以使用sdl2/2.0.10@bincrafters/stable
包来运行 sdl2 ./configure。
这是摘要:
SDL2 Configure Summary:
Building Shared Libraries
Building Static Libraries
Enabled modules : atomic audio video render events joystick haptic sensor power filesystem threads timers file loadso cpuinfo assembly
Assembly Math : mmx 3dnow sse sse2 sse3
Audio drivers : disk dummy oss alsa(dynamic) pulse(dynamic) jack(dynamic) nas(dynamic)
Video drivers : dummy x11(dynamic) opengl opengl_es2 vulkan
X11 libraries : xcursor xdbe xinerama xinput2 xinput2_multitouch xrandr xscrnsaver xshape xvidmode
Input drivers : linuxev linuxkd
Using libsamplerate : NO
Using libudev : NO
Using dbus : YES
Using ime : YES
Using ibus : NO
Using fcitx : NO
大多数谷歌结果基本上都给出了应该安装的包名,然后需要重建 sdl2。 我用我能找到的任何图书馆做到了这一点。
我发现的唯一其他提示是明确设置音频驱动程序,这就是导致 ELF 标头问题的原因。
我对 linux 以及 conan 和 cmake 都很陌生。 我正在努力确定还有什么可能会被破坏。
这可能是我机器的本地问题,但从我在整个网络上发现的点击次数来看,我认为这个普遍问题引起了更广泛的关注。
我的问题是我的设置有什么问题,我该如何解决?
编辑:
我十六进制转储了libasound.a
文件,这里是前几位:
00000000: 21 3C 61 72 63 68 3E 0A 2F 20 20 20 20 20 20 20 !<arch>./.......
00000010: 20 20 20 20 20 20 20 20 30 20 20 20 20 20 20 20 ........0.......
00000020: 20 20 20 20 30 20 20 20 20 20 30 20 20 20 20 20 ....0.....0.....
00000030: 30 20 20 20 20 20 20 20 36 33 33 30 32 20 20 20 0.......63302...
在 ELF 上阅读,这看起来不像一个 elf 文件,这可以解释为什么在假设它是一个 elf 文件的情况下加载它会失败。 所以也许这就是我的不兼容性的来源。
编辑 #1:我在libsdl.org 上发表了一篇文章。
编辑 #2:我跟进了一篇关于bincrafters/community的帖子
Eidt #3:Eric Lemanissier 创建了一个pull request ,它似乎是解决方案的一部分。
问题已解决,问题中的痕迹显示了如何解决。
最终是几个分层的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.