contiki应用程序中对“ pow”的未定义引用

时间:2019-04-15 07:43:21

标签: contiki cooja

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

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

hello-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

1 个答案:

答案 0 :(得分: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);
相关问题