Al2*_*2O3 0 c error-handling stdio strcat
我只用#include <stdio.h>在
#include <stdio.h>
void strcat(char* s, char* t);
int main()
{
char str1[12] = "hello";
char str2[] = ",world";
strcat(str1, str2);
printf("%s\n", str1);
return 0;
}
void strcat(char* s, char* t)
{
int i = 0, j = 0;
while(*s != '\0')
i++;
while((*(s + i++) = *(t + j++)) != '\0');
}
Run Code Online (Sandbox Code Playgroud)
但是当我构建它时,控制台输出:
--------------------Configuration: test16 - Win32 Debug--------------------
Linking...
LIBCD.lib(strcat.obj) : error LNK2005: _strcat already defined in test16src.obj
Run Code Online (Sandbox Code Playgroud)
为什么?不strcat中不存在stdio.h?
PS:您能否通过描述与其他文件链接的进度来解释链接错误?
strcat是一个C库函数.请参阅man strcat或POSIX(或此处为窗口)或string.h(POSIX).
因此,该符号strcat用于标准C libray(此处为LIBCD),该链接在链接阶段自动链接到程序,您将显示出现的错误.
该错误通知您,由编译源创建strcat的目标文件定义的符号test16src.o已存在于链接到的标准库(LIBCD)中test16src.o以创建最终可执行文件.
绕过此符号名称冲突会为您的实现使用不同的名称,例如my_strcat().