C错误:“对'sf_open'的未定义引用"来自libsndfile [英] C error: "Undefined reference to 'sf_open'" from libsndfile
问题描述
我正在使用Code :: Blocks测试一些代码,但我无法接受此代码:
#include< stdio.h>#include< stdlib.h>#include< sndfile.h>int main(){SNDFILE * sf;sf = sf_open("file.wav",SFM_READ,& info);//此行中发生错误...
错误是未定义对'sf_open'的引用",这不仅发生在sf_open上,而且还发生在sndfile.h中的任何函数上.
实际上,这是我到达这里的目的:
-
我首先从mega-nerd网站下载并安装了Windows x64的libsndfile(我正在使用Windows 10),并尝试运行此代码...无法正常工作,这次的错误是"sndfile.h:没有这样的文件或目录"
-
所以过了一会儿,我转到了安装目录(C:\ Program Files \ Mega-Nerd \ libsndfile \ include),并将标头复制到CodeBlocks defaut dir中,以获取标头(C:\ Program Files(x86)\ CodeBlocks \ MinGW \ include),然后我再次尝试,终于找到了标头!但是现在发生了这个错误...
所以,我想我没有以正确的方式打开标题,对此我没有太多的经验...我在互联网上的任何地方都找不到答案,我希望我能在这里找到一些运气,谢谢!
正如Jeremy所说,除了sndfile.h的include之外,还必须链接libsndfile库(它应该是.lib或.a文件./p>
仅通过链接即可他提供了
I am using Code::Blocks to test some codes, and I just can't biuld this code:
#include <stdio.h>
#include <stdlib.h>
#include <sndfile.h>
int main()
{
SNDFILE *sf;
sf = sf_open("file.wav",SFM_READ,&info); //error happens in this line
...
And the error is "undefined reference to `sf_open'", this not only happens to sf_open but also to any function from sndfile.h.
Actually here is what I did to get here:
I've first downloaded and installed libsndfile for Windows x64 (I'm using Windows 10) from mega-nerd website, and tried to run this code...didn't work, the error this time was "sndfile.h: no such file or directory"
So after a while I went to the installation dir (C:\Program Files\Mega-Nerd\libsndfile\include) and copied the headers to the CodeBlocks defaut dir for headers (C:\Program Files (x86)\CodeBlocks\MinGW\include), then I tried again and it finally found the header! But now this error is happening...
Sooo I guess I didn't open the header in the right way, I don't have much experience with this...I couldn't find the answer anywhere in the internet, I hope I get some luck here, thanks!
As Jeremy stated, apart from include for sndfile.h, you have to link against the libsndfile library (it should be a .lib or .a file.
To link it just follow the link he provided
这篇关于C错误:“对'sf_open'的未定义引用"来自libsndfile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!