0

在此处输入图像描述是否可以在 contiki-cooja 模拟器中使用 math.h 库?我在 ubuntu 18.04 LTS 上使用 contiki 3.0

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

你好世界.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();
}
/---------------------------------------------------------------------------/

生成文件

CONTIKI_PROJECT = hello-world
all: $(CONTIKI_PROJECT)

CONTIKI = ../..
include $(CONTIKI)/Makefile.include
LDFLAGS += -lm
4

1 回答 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);
于 2019-04-15T08:48:59.133 回答