未定义对memcpy_s的引用 [英] Undefined reference to memcpy_s
问题描述
我正在尝试修复对memcpy_s()
错误的未定义引用.我已经在文件中包含了string.h
,并且memcpy()
函数可以正常工作,并且我还尝试了包含memory.h
.我使用的是x64 Windows 7,并使用gcc 4.8.1进行编译.
I'm trying to fix an undefined reference to memcpy_s()
error. I've included string.h
in my file and the memcpy()
function works okay, and I've also tried including memory.h
. I'm on x64 Windows 7 and using 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);
}
内存已在调用 memory for 来自cmd终端的确切错误: Exact error from cmd terminal: 对"memcpy_s" collect2.exe的未定义引用:错误:ld返回了1个退出状态 undefined reference to "memcpy_s" collect2.exe: error: ld returned 1 exit status
据我所知,GCC 4.8不包含函数 GCC 4.8 does not include the function 这些功能最初是由Microsoft实现的,许多团体都反对将它们包含在标准中.我认为主要的反对意见是,由函数完成的错误处理涉及线程之间共享的全局回调句柄,但它们的效率也很低. These functions were originally implemented by Microsoft and many parties objected to including them in the standard. I think the main objection is that the error handling that is done by the functions involves a global callback handle that is shared between threads, but they are also quite inefficient. Further reading is available from Carlos O'Donell and Martin Sebor in Updated Field Experience With Annex K — Bounds Checking Interfaces. 这篇关于未定义对memcpy_s的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!doMemCpy(buf, 64, in, bytes)
的主函数中分配. in
是从标准输入中读取的字符串buf
has been allocated in the main function, which calls doMemCpy(buf, 64, in, bytes)
. in
is a string read from standard input
推荐答案
memcpy_s
或任何其他_s边界检查函数.这些功能在ISO 9899:2011附录K中定义,并且是可选的实现方式.使用它们之前,必须检查是否定义了__STDC_LIB_EXT1__
.memcpy_s
, or any of the other _s bounds checking functions as far as I can tell. These functions are defined in ISO 9899:2011 Annex K and they are optional to implement. Before using them you must check if __STDC_LIB_EXT1__
is defined.