OpenHarmony-如何将第三方库放到移植到OpenHarmony

本文以can-utils为例,讲述如何将can-utils集成到你的Openharmony系统

1.下载can-utils源码

通过下面命令将can-utils源码下载至Openharmony源码的third_party

cd third_party
git clone https://github.com/linux-can/can-utils.git can-utils

2. 创建BUILD.gn文件

在当前目录创建一个BUILD.gn文件, 来定义如何编译can-utils模块. 我们目前只编译了常用命令

import("//build/ohos.gni")

config("can_utils_config") {
  include_dirs = [ ".", "include" ]
  defines = [
    "AF_CAN=PF_CAN",
    "PF_CAN=29",
    "SO_RXQ_OVFL=40",
    "SCM_TIMESTAMPING_OPT_STATS=54",
    "CLOCK_TAI=11",
    "SO_TXTIME=61",
    "SCM_TXTIME=SO_TXTIME",
    "_FILE_OFFSET_BITS=64",
    "_GNU_SOURCE",
  ]
}

# 用于收集所有命令 target 名称
cmd_targets = []

foreach(cmd, [ "candump", "cansend", "cangen", "canplayer", "canbusload", "canerrsim", "canfdtest", "cansequence", "cansniffer"]) {
  ohos_executable(cmd) {
    sources = [
      "${cmd}.c",
      "lib.c",
    ]
    
    if (cmd == "canbusload") {
        sources += [ "canframelen.c" ]
    }

    configs = [ ":can_utils_config" ]
    install_enable = true
    install_images = [ "system" ]
    part_name = "can-utils"
    subsystem_name = "thirdparty"
  }

  cmd_targets += [ ":$cmd" ]
}

# 统一导出的 target:can-utils
group("can-utils") {
  deps = cmd_targets
}

3.创建bound.json

在当前目录创建一个元数据文件bound.json. 用来注册和描述can-utils组件

{
  "name": "can-utils",
  "version": "1.0.0",
  "publishAs": "code-segment",
  "component": {
    "name": "can-utils",
    "subsystem": "thirdparty",
    "syscap": [],
    "features": [],
    "adapted_system_type": ["standard"],
    "rom": "100KB",
    "ram": "100KB",
    "deps": {
      "components": [],
      "third_party": []
    },
    "build": {
      "sub_component": [
        "//third_party/can-utils:can-utils"
      ],
      "inner_kits": [],
      "test": []
    }
  }
}

4.将can-utils添加进编译系统

在平台代码中将can-utils模块添加进编译系统
我们的平台代码的位置为:vendor/hihope/rk3568/config.json
我们需要修改该文件添加以下内容:

@@ -264,6 +264,16 @@
           ]
         }
       ]
+    },
+    {
+      "subsystem": "thirdparty",
+      "components": [
+        { 
+         "component": "can-utils", 
+         "features": [] 
+       }
+      ]
+
     }
   ]
 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值