Cannot compile using ALSA

14,187

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.

Share:
14,187
tversteeg
Author by

tversteeg

Organize code, write parties

Updated on June 04, 2022

Comments

  • tversteeg
    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 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?

  • tversteeg
    tversteeg about 11 years
    But I created my own static library, libdmx.a; how can I use that library then when I remove the -static line?
  • mr.spuratic
    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 use libdmx.a in a dynamic executable (the opposite is not true, generally). Otherwise, can you recreate your library with with -shared?
  • Alan Corey
    Alan Corey over 3 years
    Wacky but same here. I have no asound.so but I do have libasound.so.