当我在c中使用strlcpy函数时,编译器给我一个错误 [英] when I use strlcpy function in c the compilor give me an error
问题描述
有人告诉我使用 strlcpy
函数而不是 strcpy
这样
#include< stdio.h>#include< string.h>无效main(){char var1 [6] =东西";char var2[7] = "世界!";strlcpy(var1, var2, sizeof(var2));printf("hello%s",var1);}
当我编译文件时它给了我以下错误:
<代码> C:\ Users \ PC-1 \ AppData \ Local \ Temp \ ccafgEAb.o:c.c :(.text + 0x45):未定义reference 到 `strlcpy'collect2.exe:错误:ld返回1退出状态
通知:我已经安装了 MinGW (适用于Windows的极简主义GNU),并且 gcc 版本是 4.7.2
出什么问题了?
对`strlcpy'的未定义引用
当链接器(collect2
,如果您使用 gcc)找不到它抱怨的函数的定义(不是声明或原型)时,就会发生这种情况,但定义功能代码的定义).
在您的情况下,可能会发生这种情况,因为没有共享对象或库具有 strlcpy
的代码进行链接.如果您确定有一个包含代码的库,并且想要链接到该库,请考虑使用传递给编译器的 -L< path_to_library>
参数指定该库的路径.
Someone told me to use the strlcpy
function instead of strcpy
like this
#include <stdio.h>
#include <string.h>
void main()
{
char var1[6] = "stuff";
char var2[7] = "world!";
strlcpy(var1, var2, sizeof(var2));
printf("hello %s", var1);
}
and when I compile the file it gives me the following error:
C:\Users\PC-1\AppData\Local\Temp\ccafgEAb.o:c.c:(.text+0x45): undefined referenc
e to `strlcpy'
collect2.exe: error: ld returned 1 exit status
notice: I have installed MinGW (Minimalist GNU for Windows) and gcc version is 4.7.2
What is the problem?
undefined reference to `strlcpy'
This happens when the linker (collect2
if you are using gcc) can not find the definition of the function it complains about (not the declaration or prototype, but the definition, where the function's code is defined).
In your case it may happen because there is no shared object or library with strlcpy
's code to link against. If you are sure there is a library with the code and you want to link against it, consider specifying the path to the library with the -L<path_to_library>
parameter passed to the compiler.
这篇关于当我在c中使用strlcpy函数时,编译器给我一个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!