How to link libs in netbeans (linux)?

2019-02-24 01:25发布

I'm trying to write a program in c++ to analyze sound. I want to use libsndfile library. I added an option -lsndfile to g++ compiler options. But I get the error: WavReader.cpp:18: undefined reference to `sf_open'

How to link the library? Please help!

#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() {
    }
}

标签: c++ netbeans g++
2条回答
叛逆
2楼-- · 2019-02-24 01:37

You need to link against -lsndfile library...make sure library path are included so it find library from correct location...check /usr/lib/ to make sure it is present on your system, or add path of correct location for your libs...

查看更多
在下西门庆
3楼-- · 2019-02-24 01:52

project properties -> linker -> libraries -> add option -> another option: -lsndfile

查看更多
登录 后发表回答