【发布时间】:2020-04-25 21:52:28
【问题描述】:
我使用lab6.c 作为驱动程序来测试每个。在我将它们分成自己的文件之前,这些功能确实有效。我应该创建一个自定义库文件。我采取的步骤是使用 wall 为文件夹中的每个 .c 文件创建一个目标文件,并使用 ar rcs 将它们链接在一起。然后我使用 ar t liblab6(name of file) 来验证每个对象是否都链接到它。不断收到链接错误“lab6.c:(.text+0x10): undefined reference to `str_len'”。
这是我的头文件中定义的第一个函数
#ifndef LAB_6_LIB_H
#define LAB_6_LIB_H
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int all_letters(char *s);
这是 .c 文件
#include "lab6lib.h"
int all_letters(char *s)
{
int i = 0;
while(s[i] != '\0'){
if(!isalpha(s[i]))
return 0;
i++;
}
return 1;
}
这是驱动程序
#include "lab6lib.h"
#include <stdio.h>
int main(void)
{
int i = str_len("all");
printf("\n%d", str_len("all"));
printf("\n%d", str_len("hahahahahahahahahahahahah"));
printf("\n%d", all_letters("poop"));
printf("\n%d", all_letters("1haha"));
printf("\n%d", all_letters("SpongeBobby"));
}
在课堂上的参考资料和我可以在网上找到的资料之间,我已经在我应该拥有的任何地方进行了定义。我什至在 github 上找到了两年前这个作业的副本,并且标题、驱动程序和 c 文件看起来都和我的一样。我已经能够完成所有步骤,但是在链接时我一直收到这个错误。我唯一没有做的就是尝试在我的 mac 上编译它。有什么我想念的吗?任何帮助将不胜感激。
【问题讨论】: