Undefined reference to `strnlen_s', strncpy_s', strncat_s'

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
source share
2 answers

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

So, since the function looks like undefined (you get implicit declaration of function errors) and don’t detect (due to undefined reference errors from the linker), I would say that you are either trying to compile this code on a system other than Microsoft (in this In the case, I would suggest using alternative functions strlen , strncpy , strncat ) or forgot to include include and asked the compiler not to include the default library (then you should fix the code and the compiler call).

+4
source

_s functions are VC ++ "safe" versions of standard library functions. You cannot use them with GCC.

C allows you to use a function without explicitly declaring it in advance. You get an “implicit declaration” warning because this is usually a behavior that programmers don't like - perhaps this means you are missing a headline.

Errors of "undefined reference" follow that those functions that were declared implicitly were not later found by the linker.

+1
source

Source: https://habr.com/ru/post/1502235/


All Articles