物联网性:构建C++示例

Iotivity : Build the C++ examples

本文关键字:C++ 示例 构建 物联网      更新时间:2023-10-16

我刚刚开始使用 iotivity,并且一直在阅读文档。在此设置页面上,在运行 c++ 示例的标题下,它讲述了如何运行示例,但在此之前,我应该先构建它们,它所引用的页面似乎Build the C++ samples缺失。

当我尝试使用 g++ 以正常方式构建示例时,它给出了一些缺失的标头错误,这意味着这不是正确的方法或需要付出很多努力。

有没有人知道如何使用物联网发布构建示例数据包?

将以下生成文件放在 iotivity/resource/examples 目录中:

IDIR=-I../include -I./../csdk/stack/include/ -I./../c_common/ -I./../oc_logger/include
CC=g++
CFLAGS=-Wall -std=c++11 $(IDIR) -loc -loctbstack -loc_logger -lpthread
SERV_OBJ = simpleserver.o
CLIENT_OBJ = simpleclient.o
%.o: %.cpp
    $(CC) -c -o $@ $^ $(CFLAGS)
#Build the simpleserver executable
all:simpleserver simpleclient
simpleserver:$(SERV_OBJ)
    $(CC) -o $@ $^ $(CFLAGS)
#Build the simpleclient executable
simpleclient:$(CLIENT_OBJ)
    $(CC) -o $@ $^ $(CFLAGS)

然后点击终端上的make。然后在两个不同的终端上执行simpleclientsimpleserver。如果您收到错误:

./simpleclient: error while loading shared libraries: liboc.so: cannot open shared object file: No such file or directory

键入以下内容:

export LD_LIBRARY_PATH=../../out/linux/x86_64/release

我研究了很多,以找到为 c++ 示例生成可执行文件的位置,最终找到了路径。

在 64 位 Ubuntu 14.04 LTS 上,当 IoT 构建如下时:

$ 斯康斯

可执行文件在路径 /iotivity/out/linux/x86_64/release/resource/examples 中为 /iotivity/resource/examples 中存在的代码创建,因此您只需转到/iotivity/out/linux/x86_64/release/resource/examples并执行 simpleserver(./simpleserver) 和 simpleclient(./simpleclient

查看此页面,了解 IoTivity 支持(和不支持)的示例:

https://wiki.iotivity.org/examples#

cd ${project_dir}/out/${TARGET_OS}/${TARGET_ARCH}/${BUILD_MODE}/resource/examples/
killall simpleserver simpleclient # make sure none are running
./simpleserver 2>&1 | tee simpleserver.log.txt &
./simpleclient 2>&1 | tee simpleclient.log.txt 

一些 c++ 示例在 1.3.0 中不起作用,而 1.2.1 应该没问题

但是如果你想从主树之外构建其他示例,我做了一个使用 gnu make 的专用项目。

希望这有帮助