6
    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
Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
Domi
  • 61
  • 1
  • 1
  • 3
  • 1
    Have you `#included` the relevant header file? – Oliver Charlesworth Sep 15 '13 at 07:30
  • 3
    @OliCharlesworth Given that OP has linker errors too, I'd say he's trying to compile a Windows-specific program on a Unix-like system. –  Sep 15 '13 at 07:31
  • Yes, the textbook, require the use of -std=c11. unfortunately I don't now to configure it. #include #include int main(void) { #if defined __STDC_LIB_EXT1__ printt("Optional functions are defined.\n"); #else printf("Optional functions are not defined.\n"); #endif return 0; } ==================== Optional functions are not defined. – Domi Sep 17 '13 at 02:21

1 Answers1

8

The strlen_s, strncpy_s and strncat_s functions are Microsoft extensions to the standard C library. They are defined in the string.h header, and are part of the libraries automatically linked.

So, since the function appear to be undefined (you get implicit declaration of function errors), and not found (due to the undefined reference errors from the linker), I'd say that you either are trying to compile this code on a non-Microsoft system (in which case, I'd suggest using the alternatives functions strlen, strncpy, strncat) or forgot the include and asked the compiler to not include default library (then you should fix the code and the compiler invocation).

Sylvain Defresne
  • 42,429
  • 12
  • 75
  • 85
  • 4
    Actually, they are documented in TR 24731 and are now in Annex K (optional) of ISO/IEC 9899:2011, the C2011 standard. They are not widely available off Microsoft, though. See [Do you use the TR 24731 'safe' functions](http://stackoverflow.com/questions/372980/do-you-use-the-tr-24731-safe-functions) for more details. – Jonathan Leffler Sep 15 '13 at 07:49