简体   繁体   English

当包含math.h库时,程序内存不会增加

[英]Program memory not increasing when including math.h library

I'm a bit of a newbie to the Atmel world. 我是Atmel世界的新手。 Once Upon a time I could write and compile C with Visual Studio but am a bit out of practice. 曾几何时,我可以使用Visual Studio编写和编译C,但是有点不实际。

So I'm trying to get an understanding of memory usage in a microcontroller ATTINY1616 . 因此,我试图了解微控制器ATTINY1616中的内存使用情况。 I opened Atmel studios, created a C executable project and chose the correct microcontroller. 我开了Atmel工作室,创建了一个C可执行项目,然后选择了正确的微控制器。 I build the project which has next to nothing in it and see that the program memory is 154 bytes . 我构建的项目几乎没有内容,并且看到程序存储器为154 bytes This is my baseline. 这是我的基准。

Now I tried to add the line #include <math.h> to see if my program memory usage would increase. 现在,我尝试添加#include <math.h>以查看程序内存使用量是否会增加。 It didn't. 没有。 Then I tried adding float a = 2.000678f; 然后我尝试添加float a = 2.000678f; inside the main . 里面的main Still no increases after building the project. 建立项目后仍然没有增加。 What am I misunderstanding here? 我在这里误会什么?

/*
* GccApplication2.c
*
* Created: 12/20/2018 9:21:43 PM
* Author : joely
*/ 

#include <avr/io.h>
#include <math.h>

int main(void)
{ 
    float a = 2.000678f;
    /* Replace with your application code */
    while (1) 
    {
    }
}

Header files typically only contain declarations of functions, not the definitions . 头文件通常仅包含功能声明 ,而不包含定义

You're not using any of the functions declared in math.h, so the library they reside in isn't getting linked into your program. 您没有使用math.h中声明的任何函数,因此它们所驻留的库不会链接到您的程序中。 If you use one of them, for example float b = sin(a) , then the contents of the math library is required and is linked in (assuming you pass -lm to gcc to do so). 如果使用其中之一,例如float b = sin(a) ,则数学库的内容是必需的,并且已链接到其中(假设您将-lm传递给gcc这样做)。

So after asking some friends with microcontroller experience I found the solution. 因此,在询问了一些具有微控制器经验的朋友之后,我找到了解决方案。

In Atmel Studio you need to go to Project-->Application Properties--->Toolchain and Change optimization to none. 在Atmel Studio中,您需要转到Project-> Application Properties ---> Toolchain,然后将优化更改为none。

Then it recognizes my floats and stores them in program memory, and when atan() is used to perform a calc it also fills up the space with the same above code. 然后,它将识别我的浮点数并将它们存储在程序内存中,当使用atan()进行计算时,它也会用上面的相同代码填充空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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