无法在ubuntu上编译libsndfile代码

问题描述 投票:2回答:1

这是我的第一篇文章。我需要为项目处理音频,因此我决定使用libsnfile。我已经安装了它,但是当我尝试用gcc somefile.cgcc `pkg-config sndfile` somefile.c编译任何.c程序时,出现“未定义”错误

/tmp/ccGTKZdy.o: En la función `convert_to_text': sndfile-to-text.c:(.text+0x193): referencia a `sf_readf_float' sin definir /tmp/ccGTKZdy.o: En la función `main': sndfile-to-text.c:(.text+0x37a): referencia a `sf_open' sin definir sndfile-to-text.c:(.text+0x3a7): referencia a `sf_strerror' sin definir sndfile-to-text.c:(.text+0x3e1): referencia a `sf_strerror' sin definir sndfile-to-text.c:(.text+0x45f): referencia a `sf_close' sin definir

任何“ sf _...”函数均未定义。我读过我可能不得不链接到图书馆,但idk如何。帮助。

c ld pkg-config libsndfile
1个回答
1
投票

仅调用pkg-config sndfile是不够的。应该是:

gcc "$(pkg-config --libs --cflags sndfile)" somefile.c

并且最近,在命令替换中,建议在反引号上使用$()https://github.com/koalaman/shellcheck/wiki/SC2006

还记得在程序中包含libsndfile标头:

#include <sndfile.h>

并添加-Wall -Wextra -pedantic选项以使编译器报告各种警告-修复代码,直到没有警告为止:

gcc "$(pkg-config --libs --cflags sndfile)" -Wall -Wextra -pedantic somefile.c
© www.soinside.com 2019 - 2024. All rights reserved.