5
    length += strnlen_s(str[i],sizeof(str[i]));

//create array to hold all strings combined

char joke[length + strnlen_s(preamble, sizeof(preamble)) + 1];

if(strncpy_s(joke, sizeof(joke), preamble, sizeof(preamble)))
{
    printf("Error copying  preamble to joke.\n");
    return 1;
}

//Concatenate strings in joke

for(unsigned int i = 0; i < strCount; ++i)
{
    if(strncat_s(joke, sizeof(joke), str[i], sizeof(str[i])))
    {

joiningstring.c:32:3: warning: implicit declaration of function ‘strnlen_s’ [-Wimplicit-function-declaration]
joiningstring.c:38:2: warning: implicit declaration of function ‘strncpy_s’ [-Wimplicit-function-declaration]
joiningstring.c:48:3: warning: implicit declaration of function ‘strncat_s’ [-Wimplicit-function-declaration]
/tmp/ccBnGxvX.o: In function `main':
joiningstring.c:(.text+0x163): undefined reference to `strnlen_s'
joiningstring.c:(.text+0x188): undefined reference to `strnlen_s'
joiningstring.c:(.text+0x1fd): undefined reference to `strncpy_s'
joiningstring.c:(.text+0x251): undefined reference to `strncat_s'
collect2: ld returned 1 exit status
4

1 回答 1

7

strlen_s和函数是标准 C 库的 Microsoftstrncpy_s扩展。strncat_s它们在string.h标题中定义,并且是自动链接的库的一部分。

因此,由于该函数似乎未定义(您收到implicit declaration of function错误),并且未找到(由于undefined reference链接器的错误),我想说您要么正在尝试在非 Microsoft 系统上编译此代码(其中在这种情况下,我建议使用替代函数strlen, strncpy, strncat) 或忘记包含并要求编译器不包含默认库(然后您应该修复代码和编译器调用)。

于 2013-09-15T07:40:40.967 回答