tversteeg tversteeg - 2 months ago 17
C Question

Cannot compile using ALSA

I am trying to create an C application on Debian GNU/Linux which uses the PortAudio interface. To do this I must compile my program with

gcc -lrt -lasound -ljack -lpthread -o YOUR_BINARY main.c libportaudio.a
from this docs.

For this I installed
libasound2-dev
, and I checked where the files are using
apt-file search libasound.so
, this is the output:

lib32asound2: /usr/lib32/libasound.so.2
lib32asound2: /usr/lib32/libasound.so.2.0.0
lib32asound2-dev: /usr/lib32/libasound.so
libasound2: /usr/lib/x86_64-linux-gnu/libasound.so.2
libasound2: /usr/lib/x86_64-linux-gnu/libasound.so.2.0.0
libasound2-dev: /usr/lib/x86_64-linux-gnu/libasound.so


So the libasound should be installed correctly, but when I compile my program with this makefile:

DMXTest: main.c libdmx.a
gcc -static -Wall main.c -L. -ldmx -lusb -lrt -lasound -ljack -lfftw3 -g -o main libportaudio.a


I get the following error:
/usr/bin/ld: cannot find -lasound
.

How can I link this library correctly?

Answer

You don't have libasound.a for -static, you will need that, or you can almost certainly just remove -static from the Makefile (likely in LDFLAGS or CFLAGS).

There's is a related Debian bug 522544, and a related Ubuntu bug #993959.

You may be able to build your own libasound from source, though as it also uses other libraries (notably libpthread.so, librt.so and libdl.so) I suspect it may remove some functionality when you build it statically, though it's supported with ./configure --enable-static at build time (or try --enable-shared=no --enable-static=yes).

FWIW, the use of static binaries is "discouraged" by the glibc maintainers, though I don't agree...