c - 文件中未定义的第一个引用符号

标签 c information-retrieval math.h

我收到此错误,但我不确定如何修复它。这是一个信息检索项目,我正在尝试使用这种类型 (1+log(freq(t,n)))*log(N/k)< 计算 tf-idf/强>。 freq(t,n)是一个词出现的频率,文件n中的tN是个数在所有文件中,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 环境中工作(并且如果您只是试图从该文件中生成可执行文件,那么您确实有一个 main 函数)。

您应该使用这样的命令进行编译,以便在链接时搜索数学库:

gcc <your_filename.c> -lm

执行此命令后,您的当前工​​作目录中应该有一个名为 a.out 的可执行文件

关于c - 文件中未定义的第一个引用符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33939026/

相关文章:

search - 有没有可以直接给出答案的搜索引擎?

c++ - 从 RGB BMP 创建灰度 BMP

c++ - 调用 SetWindowsHookEx 指向的方法

c - C语言中获取2到100之间的所有素数

text-processing - 术语聚类库?

Java 索引器速度

c - 使用 MQPUT 的 C 程序中出现段错误

c - 编译包含<math.h>的c代码时需要使用额外的选项

c - -lm 不工作,除非它在命令的末尾

c - 将 double 转换为 int 会返回向下舍入的数字吗?