未定义符号:_sf_open(OSX 上的简单音频内容)
我正在尝试进入 C++ 编程,但我在一些小细节上遇到了很大的困难。 现在,我正在尝试让下面的代码片段正常工作,显然它会编译,但不会链接。 (错误消息是本文的底部)
我正在使用 libsndfile 打开音频文件,链接器似乎找不到它的正确库文件。 这是在 OS X 10.5 上。
我从 mega-nerd.com 下载了 libsndfile 并通过常用的 configure
、make
、sudo make install
过程安装了它。 我还有什么需要做的吗?
编辑:如果有任何问题,我的系统上安装了 macports。
这是我的代码:
#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");
}
这是完整的错误消息:
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在库中链接。 您的编译器命令应类似于:
You need to link in the library. Your compiler command should look something like:
要在 Xcode 中链接库,请选择项目目标,添加新项目以将二进制文件链接到库,然后在计算机上找到 libsndfile.1.dynlib。
To link the library in Xcode, select the project target, add a new item to Link binary with libraries, and find the libsndfile.1.dynlib on your computer.