我想用C++編寫一個程序來分析聲音。我想使用libsndfile庫。我爲g ++編譯器選項添加了一個選項-lsndfile。但我得到的錯誤: WavReader.cpp:18:未定義引用'sf_open'如何鏈接netbeans(linux)中的庫?
如何鏈接庫?請幫忙!
#include <cstdlib>
#include "WavReader.h"
#include <sndfile.h>
#include <iostream>
namespace SA {
WavReader::WavReader(char* fileName, SoundProcessor* soundProcessor) {
this->fileName = fileName;
this->soundProcessor = soundProcessor;
}
void WavReader::readFile() {
SNDFILE* sf = NULL;
SF_INFO info;
info.format = 0;
sf = sf_open(this->fileName, SFM_READ, &info);
}
WavReader::~WavReader() {
}
}
顯示你的編譯命令,也許是找到了什麼NetBeans是在你的背上做。你有沒有考慮用一個好的編輯器(emacs)編輯源代碼並在終端中運行編譯命令? – 2013-02-23 12:04:19
另請注意,鏈接器標誌需要到最近版本的GNU工具鏈的命令行末尾。 – 2013-02-23 12:07:15
看來你是對的,它應該在命令行的末尾。我從「編譯器選項」中刪除了-lsndfile,並將它放到 項目屬性 - >鏈接器 - >庫 - >添加選項 - >另一個選項 ,它現在可以工作了! Netbeans把它結束了 – varan 2013-02-23 13:56:10