禁用编译器优化。 <util/delay.h> 中的功能无法按设计运行

问题描述 投票:0回答:4

我正在开发 Firebird 5 模块。那有 Atmega2560,我正在尝试编译此代码并收到此警告。

(base) pawansrinivas@Pawans-MacBook-Air Experiment-3 % mkdir -p build
(base) pawansrinivas@Pawans-MacBook-Air Experiment-3 % avr-gcc -g -Wall -O0 -mmcu=atmega328p -c Experiment-3.c -o build/Experiment-3.o
In file included from Experiment-3.c:25:
/opt/homebrew/Cellar/avr-gcc@9/9.3.0_3/avr/include/util/delay.h:112:3: warning: #warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed" [-Wcpp]
  112 | # warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed"
      |   ^~~~~~~
(base) pawansrinivas@Pawans-MacBook-Air Experiment-3 % 
c compiler-optimization avr
4个回答
3
投票

您可能正在将 AVRGCC 与 avr-libc 一起使用?

参见

为了使这些函数按预期工作,必须启用编译器优化,并且延迟时间必须是编译时已知常量的表达式。 如果不满足这些要求,所产生的延迟将更长(并且基本上是不可预测的),并且不使用浮点计算的应用程序将因链接到应用程序的浮点库例程而经历严重的代码膨胀。


0
投票

====================================================== =============== 在嵌入式系统中,如果您使用 AVR 编译器,我们会使用跨目标编译器 “

AVR-GCC Toolchain

所以如果你想使用延迟功能,你将包括

<avr/delay.h>
因为您使用 AVR 处理器系列的编译器。

希望我的回答对你有帮助。

====================================================== ===============


0
投票

您需要在编译器中启用优化,即使用标志

avr-gcc
或更高级别调用
-O1
,以便
util/delay.h
函数正常工作(并使警告消失)。

例如:

$ # with -O0 (same as with -O flag not provided at all)
$ avr-gcc -O0 -mmcu=atmega328p -c ./test.cpp -o ./test.o
In file included from ./src/main.cpp:8:0:
/usr/avr/sys-root/include/util/delay.h:112:3: warning: #warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed" [-Wcpp]
 # warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed"
   ^~~~~~~
$ # with -O1
$ avr-gcc -O1 -mmcu=atmega328p -c ./test.cpp -o ./test.o
$

更多关于 GCC 中不同优化级别的信息


0
投票

看看附图是否对您有帮助。enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.