我无法弄清楚为什么在尝试编译代码时出现以下错误。我非常感谢对此事的一些帮助。谢谢。
架构x86_64的未定义符号: “_strcat_a”,引自: _main in stringtest-4f41a8.o ld:找不到架构x86_64的符号 clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)
我的代码如下。
stringtest.c
#include "arrays.h"
#include "pointers.h"
int main(void) {
char str1[14] = "Hello";
char str2[8] = " there!";
char str3[3] = "hi";
char str4[1] = "";
char str5[32] = "abcdefghijklmnopqrstuvwxyz";
printf("%s\n", strcat_a(str1, str2));
printf("%s\n", strcat_a(str3, str4));
printf("%s\n", strcat_a(str5, str1));
return EXIT_SUCCESS;
}
arrays.h
#include <stdlib.h>
#include <stdio.h>
extern char *strcat_a(char dest[], char src[]);
arrays.c
#include "arrays.h"
char *strcat_a(char dest[], char src[]) {
int counter1 = 1;
while (dest[counter1] != '\0') {
counter1++;
}
int counter2 = 0;
while (src != '\0') {
dest[counter1++] = src[counter2++];
}
dest[++counter1] = '\0';
return dest;
}
我使用命令行构建程序cc -std = c99 -Wall -pedantic -Werror -o test1 stringtest.c