简体   繁体   English

Atmel Studio:对“_read”的未定义引用

[英]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,具体来说,

  • Project properties->Toolchain->ARM\\GNU C Compiler->Symbols: Add NDEBUG as a -D 'defined symbol'.项目属性->工具链->ARM\\GNU C Compiler->Symbols:将NDEBUG添加为-D'定义的符号'。
  • Project properties->Toolchain->ARM\\GNU Preprocessing Assembler->Symbols: Add NDEBUG as a -D 'defined symbol'.项目属性->工具链->ARM\\GNU Preprocessing Assembler->Symbols:将NDEBUG添加为-D'定义的符号'。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM