错误LNK2019和LNK1120

时间:2014-05-27 20:29:54

标签: c

这是一个众所周知的主题,但我无法找到解决方案。

我做了什么: createt和console应用程序。 添加c源文件 将我的标题文件的路径添加到“其他包括directorys” 写我的代码(或ctrl + c + crtl + v) 编译=错误

完成守则:

#include <stdio.h>
#include <stdlib.h>
#include <sndfile.h>

int main()
{
SNDFILE *sf;
SF_INFO info;
int num_channels;
int num, num_items;
int *buf;
int f,sr,c;
int i,j;
FILE *out;

/* Open the WAV file. */
info.format = 0;
sf = sf_open("file.wav",SFM_READ,&info);
if (sf == NULL)
    {
    printf("Failed to open the file.\n");
    exit(-1);
    }
/* Print some of the info, and figure out how much data to read. */
f = info.frames;
sr = info.samplerate;
c = info.channels;
printf("frames=%d\n",f);
printf("samplerate=%d\n",sr);
printf("channels=%d\n",c);
num_items = f*c;
printf("num_items=%d\n",num_items);
/* Allocate space for the data to be read, then read it. */
buf = (int *) malloc(num_items*sizeof(int));
num = sf_read_int(sf,buf,num_items);
sf_close(sf);
printf("Read %d items\n",num);
/* Write the data to filedata.out. */
out = fopen("filedata.out","w");
for (i = 0; i < num; i += c)
    {
    for (j = 0; j < c; ++j)
        fprintf(out,"%d ",buf[i+j]);
    fprintf(out,"\n");
    }
fclose(out);
return 0;
}

错误讯息:

  

1&gt; SoundIO.obj:错误LNK2019:Verweis aufnichtaufgelöstesexternes在Funktion“_main”中的符号“_sf_open”。

     

1&gt; SoundIO.obj:错误LNK2019:Verweis aufnichtaufgelöstesexternesFunktion“_main”中的符号“_sf_read_int”。

     

1&gt; SoundIO.obj:错误LNK2019:Verweis aufnichtaufgelöstesexternesFunktion“_main”中的符号“_sf_close”。

     

1&gt; C:\ Users \ Stephan \ Desktop \ BA \ Audio_Coding \ SoundIO \ Debug \ SoundIO.exe:致命错误LNK1120:3nichtaufgelösteExterne

设置:http://img5.picload.org/image/lccigod/settings.png

我想做什么?只需这样:http://ubuntuforums.org/showthread.php?t=968690

我需要什么?解决这个问题的方法(以及如何做到这一点)或一个简单的指南来实现这一目标。

3 个答案:

答案 0 :(得分:1)

链接器告诉您缺少libsndfile中函数的定义。你需要:

  1. 从其源代码编译libsndfile,并将生成的对象链接到您的程序。
  2. 链接libsndfile的导入库,以便您可以动态链接到libsndfile。
  3. 您选择的解决方案取决于您希望如何链接到libsndfile。

答案 1 :(得分:0)

来自:http://www.cprogramming.com/tutorial/compiler_linker_errors.html

  

您可能在设置编译器时遇到问题。例如,   即使您为所有功能都包含正确的头文件,   您仍然需要为链接器提供库的正确路径   有实际的实施。否则,您将获得&#34;未定义的功能&#34;   错误消息......

虽然看起来您已经在代码中正确包含了必要的标头,并且您已经编译了所有内容,但您需要静态或动态链接到libsndfile以解决链接器错误。

答案 2 :(得分:-1)

如果要包含头文件,则必须确保它们位于C ++目录的include目录中。如果它是外部文件,则必须从项目属性中将其路径添加到项目中。

相关问题