Cannot compile using ALSA
Solution 1
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...
Solution 2
To compile my code i used the following command
gcc -o rec_mic rec_mic.c -lasound
and it works perfectly, without create my own static library.
Comments
-
tversteeg almost 2 years
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 usingapt-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?
-
tversteeg about 11 yearsBut I created my own static library,
libdmx.a
; how can I use that library then when I remove the-static
line? -
mr.spuratic about 11 years
-static
controls the end result, "dynamic" doesn't prevent use of.a
files, they are really just libraries of.o
files. So you can usually uselibdmx.a
in a dynamic executable (the opposite is not true, generally). Otherwise, can you recreate your library with with-shared
? -
Alan Corey over 3 yearsWacky but same here. I have no asound.so but I do have libasound.so.