首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >树莓派的幂函数

树莓派的幂函数
EN

Stack Overflow用户
提问于 2014-06-17 16:52:55
回答 1查看 706关注 0票数 0

我在Raspberry PI中的pow()遇到了问题。我使用它,简单地像这样转动gpio引脚:

代码语言:javascript
复制
*((unsigned int *)(GPIO_PIN_ON)) = ( 1 * pow(2,16) ); // 1 << 16

GPIO_PIN_ON是我在顶部定义的常量。这可以很好地工作。我甚至不需要包含"Math.h“,但当我在其他文件中创建"GPIOsetFunction()”并使用pow()时,即使与"math.h“库一起使用,它也会给出这个错误:

代码语言:javascript
复制
gpio.c:(.text+0x38): undefined reference to `__aeabi_i2d'
gpio.c:(.text+0x48): undefined reference to `__aeabi_i2d'
>> gpio.c:(.text+0x64): undefined reference to `pow'
gpio.c:(.text+0x80): undefined reference to `__aeabi_dmul'
gpio.c:(.text+0x94): undefined reference to `__aeabi_d2iz'

在这里,它表示没有定义pow()。有人能帮帮我吗?

附言:我正在将BakingPI教程从汇编转换成C语言,我不想使用移位运算符。

下面是我在没有"math.h“和没有"-lm”的情况下成功运行的代码,如果"-lm“是解决方案,我如何能够运行它?(这是一个完整的代码OK-02的烘焙-PI教程)

P.S2:我正在使用YAGARTO编译器。

代码语言:javascript
复制
#include <sys/types.h>

void main(void);

#define GPIO_BASE 538968064 //0x20200000
#define GPIO_PIN_FUNC (GPIO_BASE+4)
#define GPIO_PIN_ON (GPIO_BASE+28)
#define GPIO_PIN_OFF (GPIO_BASE+40)

void main(void) {
register int counter = 0;
*((unsigned int *)(GPIO_PIN_FUNC)) = ( 1 * pow(2,18) ); //1 << 18
while (1 == 1) {    // forever
    *((unsigned int *)(GPIO_PIN_OFF)) = ( 1 * pow(2,16) ); //1 << 16
    counter = 4128768; //0x3f0000;
    while (counter--);
    *((unsigned int *)(GPIO_PIN_ON)) = ( 1 * pow(2,16) ); // 1 << 16
    counter =  4128768; //0x3f0000;
    while (counter--);
}
// should never get here
}   
EN

回答 1

Stack Overflow用户

发布于 2014-06-17 16:54:53

你必须链接到数学库。将-lm附加到编译(链接)命令行。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24259507

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档