首页 > 解决方案 > 对“函数名”的未定义引用

问题描述

我是一名 CS 学生,目前正在尝试学习 C。我刚开始创建自己的头文件,作为一个有趣的小项目,我想创建一个自己的库,它可以以基于字符串的方式处理大整数。只有三个文件;bignumbers.h、bignumbers.c、test.c。

大数字.h:

#ifndef BIGNUMBERS_H
#define BIGNUMBERS_H

//Typedef Declaration
typedef struct big_number{
    char digit;
    struct big_number *next_digit;
} *BIGNUMBER;


//Function Declaration
int number_length(char number[]);
BIGNUMBER create_digit(char digit);
BIGNUMBER create_number(char number[]);
//Macro Declaration

#endif // BIGNUMBERS

大数.c

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

//Actual functions
#include "bignumbers.h"
int number_length(char number[]){
    /*code to get string length*/
}

BIGNUMBER create_digit(char digit_){
    BIGNUMBER number_digit;
    number_digit = malloc(sizeof(BIGNUMBER));

    if(number_digit == NULL){
        printf("Memory allocation failed!");
        exit(EXIT_FAILURE);
    }

    number_digit->digit = digit_;
}

BIGNUMBER create_number(char number[]){
}

测试.c:

#include <stdio.h>
#include <stdlib.h>
#include "bignumbers.h"

int main(){
    number_length("1");
}

尝试编译 test.c 给我一个错误消息“未定义对'number_length'错误的引用:ld 返回 1 个退出状态”

据我所知,test.c 中没有错字。那么这里可能有什么问题呢?我知道“ld 返回 1 退出状态”是一个链接器问题,但我真的不知道是什么原因造成的。

标签: clinker-errorsheader-files

解决方案


推荐阅读