views:

156

answers:

1

I'm trying to get into C++ programming, and I'm quite struggling against the little details. Right now, I'm trying to get the snippet below to work, and apparently it will compile, but not link. (error message is a the bottom of this post)

I'm using libsndfile to open audio files, and the linker doesn't seem to find the corrent library files for it. This is on OS X 10.5.

I've downloaded libsndfile from mega-nerd.com and installed it via the ususal configure, make, sudo make install procedure. Is there anything else I need to do?

Edit: I have macports installed on my system, if that's of any concern.

Here's my code:

#include <iostream>
#include <string>
#include <sndfile.h>
#include "stereoSplit.h"
using namespace std;

int stereoSplit(string filename)
{
    cout << filename;
    SF_INFO sfinfo;
    sfinfo.format = 0;
    SNDFILE * soundfile;
    soundfile = sf_open( filename.c_str(), SFM_READ, &sfinfo );
    return 0;
}

int main (int argc, char const *argv[])
{
    return stereoSplit("testStereo.wav");
}

And here's the complete error message:

Undefined symbols:
  "_sf_open", referenced from:
      stereoSplit(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)in cc3hvkkk.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
+1  A: 

You need to link in the library. Your compiler command should look something like:

g++ mystuff.cpp -lsndfile
anon