当前位置:   article > 正文

Alsa 调试上篇:编译篇_alsa-utils编译

alsa-utils编译

1.介绍

   ALSA是Advanced Linux Sound Architecture的缩写,高级linux声音架构的简称,它在Linux操作系统上提供了音频和MIDI的支持。在2.6系列内核之后,ALSA已经成为默认的声音子系统,用来替代2.4系列内核中的oss。关于alsa的提出和设计的目的,大家可以自行百度下。本文主要讲解alsa上层提供的调试工具alsa-utils-1.1.5和alsa-lib-1.1.5。alsa官网:https://www.alsa-project.org/

平台:ubuntu 16.04

alsa版本:alsa-utils-1.1.5 alsa-lib-1.1.5

2.编译

(1)whereis:查看文件的位置  用法:whereis [-bmsu] 文件或者目录名称

参数说明:

-b :只找二进制文件

-m:只找在说明文件manual路劲下的文件

-s:只找source源文件

-u:没有说明文档的文件

 

(2)locate:配合数据库查看文件位置 用法:locate 文件或者目录名称

(3) which 查看可执行文件的位置  用法:which可执行文件名称

(4)type:用来区分某个命令到底是shell自带的,还是由shell外部的独立二进制文件提供的

(5)type命令的使用实例:

$type cd

系统会提示,cd是shell的自带命令(build-in)。

$type grep

系统会提示,grep 是一个外部命令,并显示该命令的路劲。

$type -p grep

加上-p 参数后,就相当于which命令。

2.1linux下用的编译脚本

  Linux环境下,安装软件并不是一件容易的事情;如果通过源代码编译后在安装,当然事情就更为复杂一些;现在安装各种软件的教程都非常普通;但万变不离其宗,对基础知识的扎实掌握,安装各种软件的问题就迎刃而解。Configure脚本配置工具就是基础之一,它是autoconf的工具的基本应用。

2.2configure介绍

      Configure它是个shell脚本,主要用于编译安装源代码库和软件。./configure是源代码安装的第一步,主要的作用:

  • 配置安装软件,例如:加上--with,--enable,--without,--disable等等参数
  • 检查环境是否满足安装软件的依赖关系,例如:检测是否有CC或GCC
  • 产生makefile文件
  • 用make clean删除一些临时文件

   首先可以在自己的ubuntu系统下载的软件包下面运行,./configure --help就可以查看所有的配置选项。笔者这里以alsa-lib-1.1.5的源码库为例来说明。

  1. ccion@ubuntu:~/ccion/alsa-1.1.5/alsa-lib-1.1.5$ ./configure --help
  2. `configure' configures alsa-lib 1.1.5 to adapt to many kinds of systems.
  3. Usage: ./configure [OPTION]... [VAR=VALUE]...
  4. To assign environment variables (e.g., CC, CFLAGS...), specify them as
  5. VAR=VALUE. See below for descriptions of some of the useful variables.
  6. Defaults for the options are specified in brackets.
  7. Configuration:
  8. -h, --help display this help and exit
  9. --help=short display options specific to this package
  10. --help=recursive display the short help of all the included packages
  11. -V, --version display version information and exit
  12. -q, --quiet, --silent do not print `checking ...' messages
  13. --cache-file=FILE cache test results in FILE [disabled]
  14. -C, --config-cache alias for `--cache-file=config.cache'
  15. -n, --no-create do not create output files
  16. --srcdir=DIR find the sources in DIR [configure dir or `..']
  17. Installation directories:
  18. --prefix=PREFIX install architecture-independent files in PREFIX
  19. [/usr]
  20. --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
  21. [PREFIX]
  22. By default, `make install' will install all the files in
  23. `/usr/bin', `/usr/lib' etc. You can specify
  24. an installation prefix other than `/usr' using `--prefix',
  25. for instance `--prefix=$HOME'.
  26. For better control, use the options below.
  27. Fine tuning of the installation directories:
  28. --bindir=DIR user executables [EPREFIX/bin]
  29. --sbindir=DIR system admin executables [EPREFIX/sbin]
  30. --libexecdir=DIR program executables [EPREFIX/libexec]
  31. --sysconfdir=DIR read-only single-machine data [PREFIX/etc]
  32. --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
  33. --localstatedir=DIR modifiable single-machine data [PREFIX/var]
  34. --libdir=DIR object code libraries [EPREFIX/lib]
  35. --includedir=DIR C header files [PREFIX/include]
  36. --oldincludedir=DIR C header files for non-gcc [/usr/include]
  37. --datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
  38. --datadir=DIR read-only architecture-independent data [DATAROOTDIR]
  39. --infodir=DIR info documentation [DATAROOTDIR/info]
  40. --localedir=DIR locale-dependent data [DATAROOTDIR/locale]
  41. --mandir=DIR man documentation [DATAROOTDIR/man]
  42. --docdir=DIR documentation root [DATAROOTDIR/doc/alsa-lib]
  43. --htmldir=DIR html documentation [DOCDIR]
  44. --dvidir=DIR dvi documentation [DOCDIR]
  45. --pdfdir=DIR pdf documentation [DOCDIR]
  46. --psdir=DIR ps documentation [DOCDIR]
  47. Program names:
  48. --program-prefix=PREFIX prepend PREFIX to installed program names
  49. --program-suffix=SUFFIX append SUFFIX to installed program names
  50. --program-transform-name=PROGRAM run sed PROGRAM on installed program names
  51. System types:
  52. --build=BUILD configure for building on BUILD [guessed]
  53. --host=HOST cross-compile to build programs to run on HOST [BUILD]
  54. Optional Features:
  55. --disable-option-checking ignore unrecognized --enable/--with options
  56. --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
  57. --enable-FEATURE[=ARG] include FEATURE [ARG=yes]
  58. --disable-maintainer-mode
  59. disable make rules and dependencies not useful (and
  60. sometimes confusing) to the casual installer
  61. --enable-silent-rules less verbose build output (undo: "make V=1")
  62. --disable-silent-rules verbose build output (undo: "make V=0")
  63. --enable-dependency-tracking
  64. do not reject slow dependency extractors
  65. --disable-dependency-tracking
  66. speeds up one-time build
  67. --enable-static[=PKGS] build static libraries [default=no]
  68. --enable-shared[=PKGS] build shared libraries [default=yes]
  69. --enable-fast-install[=PKGS]
  70. optimize for fast installation [default=yes]
  71. --disable-libtool-lock avoid locking (might break parallel builds)
  72. --enable-symbolic-functions
  73. use -Bsymbolic-functions option if available
  74. (optmization for size and speed)
  75. --enable-debug enable assert call at the default error message
  76. handler
  77. --enable-resmgr support resmgr (optional)
  78. --disable-aload disable reading /dev/aload*
  79. --disable-mixer disable the mixer component
  80. --disable-pcm disable the PCM component
  81. --disable-rawmidi disable the raw MIDI component
  82. --disable-hwdep disable the hwdep component
  83. --disable-seq disable the sequencer component
  84. --disable-ucm disable the use-case-manager component
  85. --disable-topology disable the DSP topology component
  86. --disable-alisp disable the alisp component
  87. --disable-old-symbols disable old obsoleted symbols
  88. --disable-python disable the python components
  89. --disable-thread-safety disable thread-safe API functions
  90. Optional Packages:
  91. --with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
  92. --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
  93. --with-pic[=PKGS] try to use only PIC/non-PIC objects [default=use
  94. both]
  95. --with-gnu-ld assume the C compiler uses GNU ld [default=no]
  96. --with-sysroot=DIR Search for dependent libraries within DIR
  97. (or the compiler's sysroot if not specified).
  98. --with-configdir=dir path where ALSA config files are stored
  99. --with-plugindir=dir path where ALSA plugin files are stored
  100. --with-pkgconfdir=dir path where pkgconfig files are stored
  101. --with-versioned shared library will be compiled with versioned
  102. symbols (default = yes)
  103. --with-debug library will be compiled with asserts (default =
  104. yes)
  105. --with-tmpdir=directory directory to put tmp socket files (/tmp)
  106. --with-softfloat do you have floating point unit on this machine?
  107. (optional)
  108. --with-libdl Use libdl for plugins (default = yes)
  109. --with-pthread Use pthread (default = yes)
  110. --with-librt Use librt for monotonic clock (default = yes)
  111. --with-wordexp Use wordexp when expanding configs (default = no)
  112. --with-alsa-devdir=dir directory with ALSA device files (default /dev/snd)
  113. --with-aload-devdir=dir directory with aload* device files (default /dev)
  114. --with-pythonlibs=ldflags
  115. specify python libraries (-lpthread -lm -ldl
  116. -lpython2.4)
  117. --with-pythonincludes=Cflags
  118. specify python C header files
  119. (-I/usr/include/python)
  120. --with-pcm-plugins=<list>
  121. build PCM plugins (default = all)
  122. --with-ctl-plugins=<list>
  123. build control plugins (default = all)
  124. --with-max-cards Specify the max number of cards (default = 32)
  125. Some influential environment variables:
  126. CC C compiler command
  127. CFLAGS C compiler flags
  128. LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
  129. nonstandard directory <lib dir>
  130. LIBS libraries to pass to the linker, e.g. -l<library>
  131. CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
  132. you have headers in a nonstandard directory <include dir>
  133. CPP C preprocessor
  134. Use these variables to override the choices made by `configure' or to help
  135. it to find libraries and programs with nonstandard names/locations.
  136. Report bugs to the package provider.

2.21.用法说明

./configure [OPTION]... [VAR=VALUE]...

2.22.几个重点参数说明。

  • --host =HOST

    指定软件运行的系统平台,如果没有指定,将会运行'config.guess'来检测。--host指定的是交叉编译工具链的前缀。

  • --build=BUILD

      指定软件安装的系统平台,如当前我们是在x86_64的ubuntu系统上,那我们的--build就可能是x86_64-unknown-linux-gnu。    如果没有指定,默认将是'--host'选项的值。

          以上二个参数,当--build和--host不同的时候就被配置文件认定文进行交叉编译,否则就是表示本地编译。从这个参数的含义来看,说明其处理的目标只有在不同平台下变现为不同的时候才有作用,而这些文件通常都跟目标平台的指令系统直接或间接相关:比如可执行文件,对于不同平台下使用的可执行文件的编码可以是完全不同的,因此必须使用对应能处理该编码的程序才能正确处理,而如果错误的使用则可能导致程序错误或者破坏文件,对于这样要处理不同平台下会出现不同编码的软件,我们就应当对它指定目标平台,以免令其错误处理;而对于文本文件,对于不同的平台同样的内容表达的含义都是相同的,因此我们不需要专门针对平台来处理。

  在交叉编译之后,我们用file ***指令,查看生成的文件类型,如果不正确,可以在源码包的目录下面查看config.log文件,看看有没有找到相应的编译工具链。

  • --enable-FEATURE[=ARG]

       软件包提供了一些默认被禁止的特性,可以使用'--enable-FEATURE'来使用它,这里'FEATURE'是特性的名字,一个特性可能或接收一个可选的参数,例如:

./configure --enable-buffers=128
  • --enable-static:生成静态链接库
  • --enable-shared:生成动态链接库
  • --prefix=PREFI X

        --prefix是最常用的选项,制作出的'makefile'会查看随此选项传递的参数,当一个包在安装时可以彻底的重新安置他的结构独立部分。

  • --bindir=DIR

       指定二进制文件的安装位置,这里的二进制文件定义为可以被用户直接执行的程序。

  • --sbindir=DIR

      指定超级二进制文件的安装位置,这是一些通常只能由超级用户执行的程序。

  • --libdir = DIR

      指定C头文件的安装位置,其他语言如C++的头文件也可以使用此选项。

      通过以上介绍,相信你已经对configure有了大体的了解。如果没能理解,也没有关系,跟着接下来的步骤,你也会生成你自己的alsa库。

2.3.交叉编译

准备阶段:在你的ubuntu主机上面创建如下文件夹:比如我的

  1. /home/ccion/ccion/alsa/usr/local
  2. ccion@ubuntu:~/ccion/alsa/usr/local$
mkdir share/arm-alsa/ share/alsa/ lib/alsa_lib/ 

   然后进入你下载的alsa-lib源码包,在源码包目前下,你会看到如下:

  1. ccion@ubuntu:~/ccion/alsa-1.1.5/alsa-lib-1.1.5$ ls
  2. acinclude.m4 config.log depcomp libtool Makefile.in test
  3. aclocal.m4 config.status doc ltconfig MEMORY-LEAK TODO
  4. alsalisp config.sub gitcompile ltmain.sh missing utils
  5. aserver configure include m4 modules version
  6. ChangeLog configure.ac INSTALL Makefile NOTES
  7. config.guess COPYING install-sh Makefile.am src

开始编译:

./configure --host=arm-linux-gnueabihf --prefix=/home/ccion/ccion/alsa/usr/local/share/arm-alsa/ --enable-shared --disable-python --witch-configdir=/home/ccion/ccion/alsa/usr/local/share/alsa --with-plugindir=/home/ccion/ccion/alsa/usr/local/lib/alsa_lib CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ LD=arm-linux-gnueabihf-ld
  1. ccion@ubuntu:~/ccion/alsa-1.1.5/alsa-lib-1.1.5$ make
  2. ccion@ubuntu:~/ccion/alsa-1.1.5/alsa-lib-1.1.5$ make install

成功编译后,你会在刚才建立的文件夹下面看到:

  1. ccion@ubuntu:~/ccion/alsa/usr/local$ tree -L 3
  2. .
  3. ├── lib
  4. │   └── alsa_lib
  5. └── share
  6. ├── alsa
  7. │   ├── alsa.conf
  8. │   ├── alsa.conf.d
  9. │   ├── cards
  10. │   ├── pcm
  11. │   ├── sndo-mixer.alisp
  12. │   ├── topology
  13. │   └── ucm
  14. └── arm-alsa
  15. ├── bin
  16. ├── include
  17. ├── lib
  18. └── share

其中,arm-alsa下的lib就是生成的库文件,以上这些文件都需要拷贝到开发板相关目录下。

验证下你的库包正确否,还记上面的命令么?

  1. ccion@ubuntu:~/ccion/alsa/usr/local/share/arm-alsa/lib$ file libasound.so.2.0.0
  2. libasound.so.2.0.0: ELF 32-bit LSB shared object, ARM,
  3. EABI5 version 1 (SYSV), dynamically linked,BuildID[sha1]=d1e68987c2a07d091210685f7610cbd13ce06210,
  4. not stripped

出现arm就表示是arm平台的文件库。接下来我们开始编译alsa官网提供的调试工具:alsa-utils-1.1.5.

3.交叉编译alsa-utils-1.1.5

不多说直接上命令:

./configure --host=arm-linux-gnueabihf --prefix=/home/ccion/ccion/alsa/usr/local/share/arm-alsa/  --disable-xmlto --with-alsa-inc-prefix=/home/ccion/ccion/alsa/usr/local/share/arm-alsa/include --with-alsa-prefix=/home/ccion/ccion/alsa/usr/local/share/arm-alsa/lib  --disable-alsamixer

注意:--prefix是你编译出来存在的位置。--with-alsa-inc-prefix和--with-alsa-prefix分别指定了交叉编译util应用所需要的alsa-lib的头文件和库文件。这里的路径一定要改为你自己的路径。--disable-alsamixer表示不编译生成alsamixer这个应用程序,因为这个程序依赖ncurses这个图形界面库。

ccion@ubuntu:~/ccion/alsa-1.1.5/alsa-utils-1.1.5$ make
sudo make install

注意:install的时候一定要用超级用户,不然会报错。

再来看看我们生成的bin文件。

  1. ccion@ubuntu:~/ccion/alsa/usr/local/share/arm-alsa/bin$ ls
  2. aconnect alsaloop alsaucm amixer aplaymidi arecordmidi aseqnet iecset
  3. alsabat alsatplg amidi aplay arecord aseqdump aserver speaker-test

file一下,

  1. ccion@ubuntu:~/ccion/alsa/usr/local/share/arm-alsa/bin$ file aplay
  2. aplay: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.32, BuildID[sha1]=e2eedccaa34695ed85e0d75294ee9c15f34049af, not stripped

以上是alsa-lib-1.1.5和alsa-utils-1.1.5的交叉编译说明和大体介绍了下configure,在下篇文章中,我将会跟你分享alsa-utils-1.1.5生成的bin的用法和相关api讲解。

 

 

 

 

 

 

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/326127
推荐阅读
相关标签
  

闽ICP备14008679号