tversteeg tversteeg - 1 year ago 88
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
, and I checked where the files are using
apt-file search
, this is the output:

lib32asound2: /usr/lib32/
lib32asound2: /usr/lib32/
lib32asound2-dev: /usr/lib32/
libasound2: /usr/lib/x86_64-linux-gnu/
libasound2: /usr/lib/x86_64-linux-gnu/
libasound2-dev: /usr/lib/x86_64-linux-gnu/

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 Source

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, and 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...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download