利用alsa库编写录音、放音代码及调试;
alsa_fy.c:18:27: fatal error: alsa/asoundlib.h: No such file or directory
#include<alsa/asoundlib.h>
^
compilation terminated.
没有找到asoundlib.h文件,安装库
apt-get install libasound2-dev
又出现没有找到函数问题
/tmp/cce5ofiH.o: In function `main':
alsa_fy.c:(.text+0x38): undefined reference to `snd_pcm_open'
alsa_fy.c:(.text+0x5c): undefined reference to `snd_pcm_hw_params_malloc'
alsa_fy.c:(.text+0x68): undefined reference to `snd_pcm_hw_params_any'
alsa_fy.c:(.text+0x90): undefined reference to `snd_pcm_hw_params_set_format'
alsa_fy.c:(.text+0x9e): undefined reference to `snd_pcm_hw_params_set_channels'
alsa_fy.c:(.text+0xb4): undefined reference to `snd_pcm_hw_params_set_rate_near'
alsa_fy.c:(.text+0xc2): undefined reference to `snd_pcm_hw_params_set_access'
alsa_fy.c:(.text+0xd2): undefined reference to `snd_pcm_hw_params_set_period_size_near'
alsa_fy.c:(.text+0xe6): undefined reference to `snd_pcm_hw_params_get_period_size'
alsa_fy.c:(.text+0xf2): undefined reference to `snd_pcm_hw_params'
alsa_fy.c:(.text+0x188): undefined reference to `snd_pcm_writei'
alsa_fy.c:(.text+0x190): undefined reference to `snd_pcm_hw_params_free'
alsa_fy.c:(.text+0x1a2): undefined reference to `snd_pcm_close'
collect2: error: ld returned 1 exit status
程序链接的时候,找不到链接库。在gcc的参数里面加了 -lasound 选项。
可以编译通过的写法:gcc -o main main.o -lasound
gcc中库的链接顺序是从右往左进行,所以要把最基础实现的库放在最后,这样左边的lib就可以