[英]Atmel Studio: undefined reference to `_read'
I started receiving the following Linker error with Atmel Studio:我开始在 Atmel Studio 中收到以下链接器错误:
c:/program files (x86)/atmel/studio/7.0/toolchain/arm/arm-gnu-toolchain/bin/../lib/gcc/arm-none-eabi/6.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m\libc.a(lib_a-readr.o):
In function `_read_r':
C:\Users\Administrator\Documents\myproj\Debug\readr.c(1,1): error: undefined reference to `_read'
This happened after I added a virtual
method to my project.这是在我向项目添加
virtual
方法之后发生的。 What is going on?到底是怎么回事?
Answer originally pulled from this site . 答案最初是从此站点提取的。
What's going on is that a built-in __cxa_pure_virtual
defaults to using _read
and _write
via printf
. 发生的是,内置的
__cxa_pure_virtual
默认使用通过printf
使用_read
和_write
。 To fix, explicitly define that handler to do something else. 要修复,请显式定义该处理程序以执行其他操作。
extern "C" void __cxa_pure_virtual();
extern "C" void __cxa_pure_virtual() {
// Add custom handler here
while(1);
}
In my case, I traced it to an issue with the asf defining assert() to something invalid when 'NDEBUG' is not defined in the project compile\\link symbols.在我的情况下,我将其追溯到 asf 将 assert() 定义为无效的问题,当项目 compile\\link 符号中未定义“NDEBUG”时。
Specifically,具体来说,
In my case, this issue was related to the linker settings of the project configuration.就我而言,此问题与项目配置的链接器设置有关。
By setting the linker settings "Additional Specs" to " Use syscall stubs (--specs=nosys.specs) ", empty syscall implementations for posix system calls like read and write are provided.通过将链接器设置“Additional Specs”设置为“ Use syscall stubs (--specs=nosys.specs) ”,可以为 posix 系统调用(如读取和写入)提供空的系统调用实现。
These settings are located under这些设置位于
Project Properties -> Toolchain -> ARM/GNU Linker -> General -> Additional Specs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.