Undefined reference to memcpy_s
I am trying to fix the undefined link for an error memcpy_s()
. I included string.h
in my file and the function memcpy()
works fine and I also tried to include memory.h
. I am on x64 Windows 7 and use gcc 4.8.1 to compile.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void doMemCopy(char* buf, size_t buf_size, char* in, int chr) {
memcpy_s(buf, buf_size, in, chr);
}
the memory for is buf
allocated in the main function that calls doMemCpy(buf, 64, in, bytes)
. in
is the line read from standard input
Exact error from terminal cmd:
undefined reference to "memcpy_s" collect2.exe: error: ld returned 1 exit status
source to share
GCC 4.8 does not include a feature memcpy_s
or any of the other feature bounds checking as far as I can tell. These functions are defined in ISO 9899: 2011 Annex K and are optional to implement. Before using them, you should check if they exist __STDC_LIB_EXT1__
.
These features were originally implemented by Microsoft and many parties objected to their inclusion in the standard. I think the main objection is that the error handling performed by functions includes a global callback descriptor that is shared by threads, but they are also pretty inefficient.
Additional reading is available from Carlos O'Donell and Martin Sebor at Updated Experience with KB Application Verification Interfaces .
source to share