2012-12-18 25 views
0

我正在嘗試使用libsndfile。我用g ++也不是很好。安裝libsndfile的方法似乎是使用「make install」。我真的可以這樣做,所以我將它編譯到一個目錄中。如何將libsndfile編譯到項目中?

我試圖編譯這裏的教程:
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 ++。

+0

編譯提供更多信息你的環境,什麼GNU/Linux發行版,我認爲你可以在你的系統中安裝libs,然後編譯你的程序米 – rendon

回答

4

如果配置與安裝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 
+0

非常感謝,可以靜態鏈接庫嗎? – SamFisher83

+0

那麼,你需要一個庫的靜態版本,然後在「-lsndfile」之前加上「-static」就可以了。 –

2

在GNU/Linux中Debian squeeze我已經安裝了libsndfile1庫和程序編譯沒有問題。

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

您需要安裝與包管理器或源代碼庫。

+0

問題是我沒有在該計算機上安裝軟件包的能力 – SamFisher83

+0

爲什麼?你不提供很多信息,對不起! – rendon