【问题标题】:How to compile libsndfile into a project?如何将 libsndfile 编译到项目中?
【发布时间】:2012-12-05 03:33:50
【问题描述】:

我正在尝试使用 libsndfile。我对 g++ 也不是很好。安装 libsndfile 的方法似乎是使用“make install”。我真的可以,所以我把它编译到了一个目录中。

我在这里尝试编译教程:
http://parumi.wordpress.com/2007/12/16/how-to-write-wav-files-in-c-using-libsndfile/

当我尝试以下操作时:

g++  -Isrc/ test.c

我明白了:

/tmp/ccq5fhbT.o: In function SndfileHandle::SndfileHandle(char const*, int, int, int, int)':
test.c:(.text._ZN13SndfileHandleC1EPKciiii[SndfileHandle::SndfileHandle(char const*, int, int, int, int)]+0xf4): undefined reference to sf_open'
/tmp/ccq5fhbT.o: In function SndfileHandle::write(float const*, long)':
test.c:(.text._ZN13SndfileHandle5writeEPKfl[SndfileHandle::write(float const*, long)]+0x27): undefined reference to sf_write_float'
/tmp/ccq5fhbT.o: In function SndfileHandle::SNDFILE_ref::~SNDFILE_ref()':
test.c:(.text._ZN13SndfileHandle11SNDFILE_refD1Ev[SndfileHandle::SNDFILE_ref::~SNDFILE_ref()]+0x20): undefined reference to sf_close'
collect2: ld returned 1 exit status

当我尝试执行以下操作时:

g++ -lsndfile -Isrc/ test.c

我明白了

/usr/bin/ld: cannot find -lsndfile
collect2: ld returned 1 exit status

我不确定我需要为 g++ 提供哪些开关。

【问题讨论】:

  • 提供更多关于你的环境的信息,什么 GNU/Linux 发行版,我认为你可以在你的系统中安装这些库,然后编译你的程序。

标签: g++ libsndfile


【解决方案1】:

在 GNU/Linux Debian 挤压中,我已经安装了 libsndfile1 库,程序编译没有问题。

# apt-get install libsndfile1-dev
$ g++ -w -o testsnd testsnd.c -lsndfile

您需要使用包管理器或从源代码安装库。

【讨论】:

  • 问题是我无法在该计算机上安装软件包
  • 为什么?您没有提供太多信息,抱歉!
【解决方案2】:

如果您使用以下命令配置和安装 libsndfile:

./configure --prefix=$HOME/local
make
make install

然后您应该设置/修改您的 LD_LIBRARY_PATH 变量:

export $LD_LIBRARY_PATH=$HOME/local/lib

然后编译

g++ -I $HOME/local/include -L $HOME/local/lib -lsndfile testsnd.c -o  testsnd

【讨论】:

  • 非常感谢,可以静态链接库吗?
  • 嗯,你需要一个静态版本的库,然后在“-lsndfile”之前添加“-static”。
猜你喜欢
  • 2014-02-27
  • 2016-12-12
  • 2011-09-18
  • 2012-07-19
  • 2015-07-06
  • 2017-11-13
  • 1970-01-01
  • 1970-01-01
  • 2022-01-06
相关资源
最近更新 更多