gpt4 book ai didi

g++ - 如何将libsndfile编译成项目?

转载 作者:行者123 更新时间:2023-12-05 08:59:32 25 4
gpt4 key购买 nike

我正在尝试使用 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++ 什么开关。

最佳答案

如果您使用以下命令配置和安装 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

关于g++ - 如何将libsndfile编译成项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13924318/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com