c - 对“函数名”的未定义引用
问题描述
我是一名 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 退出状态”是一个链接器问题,但我真的不知道是什么原因造成的。
解决方案
推荐阅读
- apache - 为域和子域、Apache2、Ubuntu 声明 VirtualHost
- .net-core - .NET Core 3.1 Websocket 错误:指定的网络名称不再可用
- r - 将 dbplyr 查询保存到 postgree
- amazon-web-services - 使用 boto3 更新 ecs 的最小计数
- javascript - Rock, Paper, Scissor Project (Odin Project) - Button Assistance
- mysql - 当我发布到我最新的 MySQL 表时出现 ReactJS 错误
- cron - 在 crontab 中拥有多个 MAILTO 环境变量的 Ansbile 方法
- android - 如何向片段中的工具栏添加功能
- c++ - 默认构造函数不能被引用错误(Visual Studios 2019)
- python - 为什么在尝试使用 Line3D 对象时 matplotlib 3d 动画不起作用