在contiki应用程序中未定义引用`pow'

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

enter image description here是否可以在contiki-cooja模拟器中使用math.h库?我在ubuntu 18.04 LTS上使用contiki 3.0

我尝试在hello-world应用程序的makefile中添加LDFLAGS + = -lm。此外,我还尝试在Makefile.include文件中添加-lm。事情不起作用。添加-lm的正确位置是什么。

你好,world.c

#include "contiki.h"

#include <stdio.h> /* For printf() /
#include <math.h>
#define DEBUG DEBUG_PRINT
static float i;
/---------------------------------------------------------------------------/
PROCESS(hello_world_process, "Hello world process");
AUTOSTART_PROCESSES(&hello_world_process);
/---------------------------------------------------------------------------/
PROCESS_THREAD(hello_world_process, ev, data)
{
PROCESS_BEGIN();
i = 2.1;
printf("Hello, world\n");
printf("%i\n", (int)pow(10,i));
printf("%i\n", (int)(M_LOG2Ei));
PROCESS_END();
}
/---------------------------------------------------------------------------/

Makefile文件

CONTIKI_PROJECT = hello-world
all: $(CONTIKI_PROJECT)

CONTIKI = ../..
include $(CONTIKI)/Makefile.include
LDFLAGS += -lm
contiki cooja
1个回答
0
投票

首先,您可以向Contiki添加外部库:

TARGET_LIBFILES = -lm

确保你在include $(CONTIKI)/Makefile.include线之前这样做,而不是之后!

第二,你在编译哪个平台? msp430平台在数学库中没有pow函数。它们只有powf函数在单精度浮点数上运算,而内置(内在)函数pow在整数运算。

如果要对浮点数进行操作,请将代码更改为:

float f = 2.1;
pow(10, f);

对此

float f = 2.1;
powf(10, f);
© www.soinside.com 2019 - 2024. All rights reserved.