Audio Playback Program using ALSA-Lib on Colibri iMX6

I am trying to play audio using ALSA Lib on iMX6 running Linux. I am using the Minimal Playback Program mentioned here. I am able to compile the program but the Cross GCC Linker gave me linker errors. After researching about the linking errors, I found out that I need to add -lasound to the linker flags.

After adding the linker flag I am still having errors. The console output is as follows:

16:21:06 **** Incremental Build of configuration Debug for project sound ****
make all 
/home/gcc-linaro-5.2-2015.11-2-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/5.2.1/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lasound
Building target: sound
Invoking: Cross GCC Linker
collect2: error: ld returned 1 exit status
arm-linux-gnueabihf-gcc -L/home/alsa-lib-1.1.2/include -L/srv/nfs/rootfs/usr/lib -Wl,-rpath-link,/srv/nfs/rootfs/usr/lib -L/srv/nfs/rootfs/lib -Wl,-rpath-link,/srv/nfs/rootfs/lib -o "sound"  ./play.o   -lasound
makefile:29: recipe for target 'sound' failed
make: *** [sound] Error 1

16:21:06 Build Finished (took 159ms)

Can someone help me resolve this error?

Also, are there any LGPL licensed libraries that could be used for audio playback functionality ?

Thanks.

Can you share your compilation command or Makefile perhaps which you use to compile? A Makefile like below can be used for compilation.

CC = ${HOME}/Toradex/gcc-linaro/bin/arm-linux-gnueabihf-gcc
SYSROOTS ?= /usr/local/oecore-x86_64/sysroots
INCLUDES = -I${SYSROOTS}/armv7at2hf-vfp-neon-angstrom-linux-gnueabi/usr/include
LIB_PATH = -L${SYSROOTS}/armv7at2hf-vfp-neon-angstrom-linux-gnueabi/lib/
LIBS = -lasound
CFLAGS = -O2 -g -mfloat-abi=hard --sysroot=${SYSROOTS}/armv7at2hf-vfp-neon-angstrom-linux-gnueabi/

all:
	${CC} ${CFLAGS} ${LIB_PATH} ${LIBS} ${INCLUDES} -o monowavplayback monowavplayback.c

clean:
	rm -rf monowavplayback

The sysroots variable in the above Makefile points to the SDK generated from OpenEmbedded. I used this sample code to test audio playback of wav file on Colibri iMX6.

I am using sysroots point to iMX6_Linux as mentioned in this link.

I used the sample code provided by you and I am having same linker error.

08:37:40 **** Incremental Build of configuration Debug for project sound ****
make all 
Building file: ../play.c
Invoking: Cross GCC Compiler
arm-linux-gnueabihf-gcc -I/home/alsa-lib-1.1.2/include -O0 -march=armv7-a -fno-tree-vectorize -mthumb-interwork -mfloat-abi=hard -mtune=cortex-a9 -Wno-poison-system-directories -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"play.d" -MT"play.o" -o "play.o" "../play.c"
Finished building: ../play.c
 
Building target: sound
Invoking: Cross GCC Linker
arm-linux-gnueabihf-gcc -L/home/alsa-lib-1.1.2/include -L/srv/nfs/rootfs/usr/lib -Wl,-rpath-link,/srv/nfs/rootfs/usr/lib -L/srv/nfs/rootfs/lib -Wl,-rpath-link,/srv/nfs/rootfs/lib -o "sound"  ./play.o   -lasound
/home/gcc-linaro-5.2-2015.11-2-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/5.2.1/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lasound
makefile:29: recipe for target 'sound' failed
collect2: error: ld returned 1 exit status
make: *** [sound] Error 1

08:37:40 Build Finished (took 112ms)

I am attaching the makefile generated by eclipse.
link text

Thank you for the support.

Hi

If you use the binary image to link against (and your buildmachine’s header file) then you would need to create unversioned symlinks to the shared libraries as described here.

I.e. you have to execute the following excerpt:

cd /srv/nfs/rootfs/usr/lib
sudo sh -c "ls -w 1 | grep '\.so\.[0-9]*\.[0-9]*\.[0-9]*$' | sed -r 's/(.*\.so)(\.[0-9]*\.[0-9]*\.[0-9]*$)/ln -s \1\2 \1/' > makesymlinks.sh"
sudo chmod +x makesymlinks.sh
sudo ./makesymlinks.sh
sudo rm makesymlinks.sh

Max

Hi Max.
I have created the symlink before and was still getting the error.

I decided to go with the other approach of using SDK. I run the environment_sourcing script and created a symlink to the sysroot found in the sdk package. The linker still gives the error “cannot find -lasound”

Can you please help me detect the problem?

Thank you.

And does libasound.so actually exist in one of the paths you pass to the linker with one of the -L statements?

If only playback, why not use the command aplay of the own ALSA?


Cleiton Bueno

Blog | Linkedin | B2Open

I have the path that contains libasound.so added to the -L statement.

For some reason, the arm-linux-gnueabihf/bin/ld: cannot find /lib/libc.so.6 , /usr/lib/libc_nonshared.a, /lib/ld-linux-armhf.so.3

I wonder why ld is looking into Ubuntu’s root folder instead of sourced SDK path?

Using aplay would have been my best choice, but I also want volume control with it.

Can you add --sysroot=/srv/nfs/rootfs to your linker flags? i.e. to were you specify your -L options.

I added the flag but it is showing me the same error.

I tried to build a alsa helloworld using:

  • A toolchain downloaded from Linaro
  • The build hosts headers
  • The rootfs from our binary image to link against modified with the makesymlinks.sh trick mentioned above.

I ended up setting the eclipse compiler options to:

-march=armv7-a -fno-tree-vectorize -mthumb-interwork -mfloat-abi=hard -mtune=cortex-a9 -Wno-poison-system-directories -I/usr/include

And the linker options to:

-L/srv/nfs/rootfs/usr/lib -Wl,-rpath-link,/srv/nfs/rootfs/usr/lib -lasound

With this I get a successful build.

19:43:17 **** Build of configuration Debug for project audio_hello ****
make all 
Building file: ../audio_main.c
Invoking: Cross GCC Compiler
arm-linux-gnueabihf-gcc -O0 -march=armv7-a -fno-tree-vectorize -mthumb-interwork -mfloat-abi=hard -mtune=cortex-a9 -Wno-poison-system-directories -I/usr/include -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"audio_main.d" -MT"audio_main.o" -o "audio_main.o" "../audio_main.c"
Finished building: ../audio_main.c
 
Building target: audio_hello
Invoking: Cross GCC Linker
arm-linux-gnueabihf-gcc -L/srv/nfs/rootfs/usr/lib -Wl,-rpath-link,/srv/nfs/rootfs/usr/lib -lasound -o "audio_hello"  ./audio_main.o   
Finished building target: audio_hello
 

19:43:17 Build Finished (took 111ms)

Your replies so far hint that you changed your approach of what or how compiler / headers / rootfs is used, so if the above does not help I suggest you describe of how your current setup looks like, and what your current eclipse settings really are and show the console output of a build after you did run a clean project.

Max