之后,您应该在当前工作目录中有一个名为a.out的可执行文件
我得到了这个错误,我不知道如何修复它。这是一个信息检索项目,我试图使用此类型(1+log(freq(t,n))*log(n/k)计算tf idffreq(t,n)是单词的频率,文件n中的t和n为文件总数,k包含单词t的文件数。
Undefined first referenced
symbol in file
log /var/tmp//ccx8E8Y1.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
这是我得到错误的函数(我在开始时有#include <math.h>
):
void makeTF_IDF(char** words,double** weight,char** str){
int i,j,n,f;
char nameout[1024],line[1024];
double tf,idf[1443],t;
FILE *fin;
for(i=0;i<1443;i++){
n=0;
for(j=0;j<26;j++){
strcpy(nameout,strtok(str[j],"."));
strcat(nameout,"out.txt");
fin=fopen(nameout,"r");
while(1){
if(fgets(line,1024,fin)==NULL) break;
if(strstr(line,words[i])!=NULL){
n++;
break;
}
}
fclose(fin);
}
t=26/n;
idf[i]=log(t);
}
for(i=0;i<1443;i++){
for(j=0;j<26;j++){
f=0;
strcpy(nameout,strtok(str[j],"."));
strcat(nameout,"out.txt");
fin=fopen(nameout,"r");
while(1){
if(fgets(line,1024,fin)==NULL) break;
if(strstr(line,words[i])!=NULL) f++;
}
weight[j][i]=(log(1+f))*idf[i];
fclose(fin);
}
}
}
我想您正在unix环境中工作(如果您只想从这个文件中生成一个可执行文件,那么您确实有一个主函数)。
您应该使用这样的命令进行编译,以便在链接时搜索数学库:
gcc <your_filename.c> -lm
在这个命令