openharmony_3.1 使用第三方so文件
小小团子
发布于 2023-3-31 16:49
浏览
1收藏
1、项目目录
├── build
│ ├── BUILD.gn
│ └── libbehaviortree.so //第三方so文件
├── BUILD.gn
├── bundle.json
├── include
│ ├── impl_utils.h
│ ├── single_instance.h
│ ├── task_behavior.h
│ ├── task_executor.h
│ ├── task.h
│ └── util.h
└── src
├── task.cpp
├── task_executor.cpp
└── task_test.cpp
2、动态库编译配置
-
动态库路径 build/libbehaviortree.so
-
动态库配置build/BUILD.gn
import("//build/ohos.gni") ohos_prebuilt_shared_library("behavior_tree_lib") { source = "./libbehaviortree.so" install_enable = true subsystem_name = "applications" part_name = "task_thread" }
3、使用动态库
- 动态库调用配置 BUILD.gn
import("//build/ohos.gni")
config("task_thread_config") {
cflags_cc = [
"-frtti",
"-fexceptions",
]
}
ohos_executable("task_thread") {
sources = [
"src/task_test.cpp",
"src/task_executor.cpp",
"src/task.cpp",
]
configs = [":task_thread_config"]
include_dirs = [
"include",
"//third_party/BehaviorTree.CPP/include"
]
deps = ["//applications/task/build:behavior_tree_lib"]
part_name = "task_thread"
subsystem_name = "applications"
}
- bundle.json配置
{
"name": "@ohos/task_thread",
"description": "The repository contains the Abseil C++ library code. Abseil is an open-source collection of C++ code (compliant to C++11) designed to augment the C++ standard library.",
"version": "3.1",
"license": "Apache V2",
"publishAs": "code-segment",
"segment": {
"destPath": "applications/task"
},
"dirs": {},
"scripts": {},
"component": {
"name": "task_thread",
"subsystem": "applications",
"syscap": [],
"features": [],
"adapted_system_type": [],
"rom": "",
"ram": "",
"deps": {
"components": [
],
"third_party": []
},
"build": {
"sub_component": [
"//applications/task:task_thread",
"//applications/task/build:behavior_tree_lib"
],
"inner_kits": [
],
"test": []
}
}
}
4、编译可执行程序
./build.sh --product-name rk3568 --ccache --build-target task_thread
5、测试结果
- 修改系统目录权限,使目录可读可写 mount -o remount,rw /
- 发送编译程序和so动态库到开发板 hdc_std file send libbehaviortree.so /data
- 拷贝so到 /lib/目录mv /data/libbehaviortree.so /lib/
- 运行结果
分类
已于2023-3-31 17:07:14修改
赞
5
收藏 1
回复
相关推荐
最好提交个仓库,不然无法实验或者测试