我正在尝试在Debian GNU/Linux上创建一个使用PortAudio接口的C应用程序。要做到这一点,我必须从这个docs.用gcc -lrt -lasound -ljack -lpthread -o YOUR_BINARY main.c libportaudio.a编译我的程序
为此,我安装了libasound2-dev,并检查了文件使用apt-file search libasound.so的位置,输出如下:
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所以libasound应该是正确安装的,但是当我用这个makefile编译我的程序时:
DMXTest: main.c libdmx.a
gcc -static -Wall main.c -L. -ldmx -lusb -lrt -lasound -ljack -lfftw3 -g -o main libportaudio.a我得到以下错误:/usr/bin/ld: cannot find -lasound。
如何正确链接此库?
发布于 2013-03-09 21:23:30
您没有用于-static的libasound.a,您将需要它,或者几乎可以肯定的是,您可以直接从Makefile中删除-static (可能在LDFLAGS或CFLAGS中)。
有一个相关的Debian bug 522544和一个相关的Ubuntu bug #993959。
你可以从源代码构建你自己的libasound,尽管它也使用了其他库(特别是libpthread.so,librt.so和libdl.so),我怀疑当你静态构建它时,它可能会删除一些功能,尽管它在构建时支持./configure --enable-static (或者尝试--enable-shared=no --enable-static=yes)。
顺便说一句,静态二进制文件的使用对于glibc维护者来说是"discouraged“的,尽管我不同意...
发布于 2014-01-15 02:57:10
为了编译我的代码,我使用了以下命令
gcc -o rec_mic rec_mic.c -lasound它可以完美地工作,而不需要创建我自己的静态库。
https://stackoverflow.com/questions/15310934
复制相似问题