【C++三方库移植】移植BehaviorTree.CPP到OpenHarmony标准系统① 原创 精华

离北况归
发布于 2023-6-26 17:09
浏览
3收藏

@toc

1. 为BehaviorTree.CPP编写BUILD.gn进行Rom集成

  • Rom集成笔者开发环境:
    • wsl2+ubuntu18.04
    • OpenHarmony 3.2 release 源码
    • 润和大禹200开发板

1.2 修改build/subsystem_config.json,新增子系统behaviortree定义

在源码/build/subsystem_config.json中增加子系统behaviortree

  "behaviortree": {
    "path": "third_party/behaviortree",
    "name": "behaviortree"
  }

1.3 修改vendor/hihope/rk3568/config.json文件将behaviortree添加至rk3568开发板

    {
      "subsystem": "behaviortree",
      "components": [
        {
          "component": "behaviortree",
          "features": []
        }
      ]
    }

1.4 在OpenHarmony标准系统源码下third_party下放置BehaviorTree.CPP源码

1.5 third_party/behaviortree目录下添加bundle.json文件

  • 特别说明:ohos.build不再使用,OpenHarmony源码中全部使用bundle.json

  • bundle.json文件:

{
  "name": "@ohos/behaviortree",
  "description": "",
  "version": "",
  "license": "",
  "publishAs": "",
  "segment": {
      "destPath": "third_party/behaviortree"
  },
  "dirs": {},
  "scripts": {},
  "readmePath": {
  },
  "component": {
      "name": "behaviortree",
      "subsystem": "behaviortree",
      "syscap": [],
      "features": [],
      "adapted_system_type": [],
      "rom": "",
      "ram": "",
      "deps": {
          "components": [],
          "third_party": []
      },
      "build": {
          "sub_component": [
            "//third_party/behaviortree:lexy_file",
            "//third_party/behaviortree:bt_sample_nodes",
            "//third_party/behaviortree:behaviortree_cpp",
            "//third_party/behaviortree:dummy_nodes_dyn",
            "//third_party/behaviortree:crossdoor_nodes_dyn",
            "//third_party/behaviortree:movebase_node_dyn",
            "//third_party/behaviortree:t01_build_your_first_tree",
            "//third_party/behaviortree:t02_basic_ports",
            "//third_party/behaviortree:t03_generic_ports",
            "//third_party/behaviortree:t05_crossdoor",
            "//third_party/behaviortree:t04_reactive_sequence",
            "//third_party/behaviortree:t06_subtree_port_remapping",
            "//third_party/behaviortree:t07_load_multiple_xml",
            "//third_party/behaviortree:t08_additional_node_args",
            "//third_party/behaviortree:t09_scripting",
            "//third_party/behaviortree:t10_observer",
            "//third_party/behaviortree:t11_replace_rules",
            "//third_party/behaviortree:ex01_wrap_legacy",
            "//third_party/behaviortree:ex02_runtime_ports",
            "//third_party/behaviortree:ex03_ncurses_manual_selector",
            "//third_party/behaviortree:ex04_waypoints"
          ],
          "inner_kits": [],
          "test": []
      }
  }
}

1.6 BehaviorTree.CPP编译gn化,在third_party/behaviortree下添加BUILD.gn脚本文件

  • third_party/behaviortree/BUILD.gn配置的模块有

    • so
      • libbehaviortree_cpp.z.so
      • libmovebase_node_dyn.z.so
      • libcrossdoor_nodes_dyn.z.so
      • libdummy_nodes_dyn.z.so
    • .a
      • liblexy_file.a
      • libbt_sample_nodes.a
    • 可执行文件
      • t01_build_your_first_tree
      • t02_basic_ports
      • t03_generic_ports
      • t04_reactive_sequence
      • t05_crossdoor
      • t06_subtree_port_remapping
      • t07_load_multiple_xml
      • t08_additional_node_args
      • t09_scripting
      • t10_observer
      • t11_replace_rules
      • ex01_wrap_legacy
      • ex02_runtime_ports
      • ex03_ncurses_manual_selector
      • ex04_waypoints
  • 模块之间的依赖关系

    • libbehaviortree_cpp.z.so依赖lexy_file.a
    • libcrossdoor_nodes_dyn.z.so依赖libbehaviortree_cpp.z.so
    • libmovebase_node_dyn.z.so依赖libbehaviortree_cpp.z.so
    • 所有的可执行文件都依赖libbt_sample_nodes.a和libbehaviortree_cpp.z.so
  • third_party/behaviortree/BUILD.gn文件如下:

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

# 公共配置

config("public_config"){
    ldflags = [
       #"-lstdc++",
       #用-lc++替代-lstdc++
       "-lc++",
       "-Wl",
       "-lm",
       "-lc",
       "-lpthread",
    ]

}
##############################################################################

# liblexy_file.a

config("lexy_file_config"){
    #cflags_cc是用来存储专门针对 C++ 语言编译器的选项,只会被 C++ 编译器使用。
    cflags_cc = [
       "-O3",
       "-DNDEBUG",  
       "-Wpedantic", 
       "-pedantic-errors", 
       "-Werror", 
       "-Wall", 
       "-Wextra", 
       "-Wconversion", 
       "-Wsign-conversion", 
       "-Wno-parentheses", 
       "-Wno-unused-local-typedefs", 
       "-Wno-array-bounds", 
       "-Wno-maybe-uninitialized", 
       "-Wno-restrict", 
       "-std=gnu++20",
    ]
}

ohos_static_library("lexy_file") {
    output_name = "lexy_file" # 可选,模块输出名

    sources = [
         "//third_party/behaviortree/3rdparty/lexy/src/input/file.cpp",
    ]

    defines = [
    ]

    configs = [ 
         ":lexy_file_config", 
         ":public_config",
    ] 

    include_dirs = [
         "3rdparty/lexy/include",
    ]

    part_name = "behaviortree"

    subsystem_name = "behaviortree"
}

##############################################################################

# libbt_sample_nodes.a

config("bt_sample_nodes_config"){
    #cflags_cc是用来存储专门针对 C++ 语言编译器的选项,只会被 C++ 编译器使用。
     cflags_cc = [
        "-O3", 
        "-DNDEBUG",    
        "-Wpedantic",   
        "-std=gnu++17",

        # 为了消除编译报错添加的
        "-fexceptions",
        "-frtti",
        "-Wno-unused-function",
     ]
}

ohos_static_library("bt_sample_nodes") {
    sources = [
        "sample_nodes/crossdoor_nodes.cpp",
        "sample_nodes/dummy_nodes.cpp",
        "sample_nodes/movebase_node.cpp",
    ]

    defines = [
    ]

    configs = [ 
         ":bt_sample_nodes_config", 
         ":public_config",
    ] 

    include_dirs = [
         "include",
         "sample_nodes"
    ]

    part_name = "behaviortree"

    subsystem_name = "behaviortree"
}

##############################################################################

# libbehaviortree_cpp.so

config("behaviortreecpp_config"){
    cflags_cc = [
        # 为了编译libbehaviortree_cpp.so原生库中添加的编译器标志
        "-O3", 
        "-DNDEBUG",  
        "-fPIC",    
        "-Wpedantic",  
        "-Wall",  
        "-Wextra",  
        "-std=gnu++20",

        # 为了消除shared_library.cpp编译报错添加-fexceptions
        "-fexceptions",
        "-frtti",
        "-Wno-deprecated-volatile",
        "-Wno-unused-lambda-capture",
    ]

    include_dirs = [
         ".",
         "include",
         "3rdparty",
         "3rdparty/lexy/include",
    ]

}

ohos_shared_library("behaviortree_cpp") {
    output_name = "behaviortree_cpp" # 可选,模块输出名

    sources = [
        "src/action_node.cpp",
        "src/basic_types.cpp",
        "src/behavior_tree.cpp",
        "src/blackboard.cpp",
        "src/bt_factory.cpp",
        "src/decorator_node.cpp",
        "src/condition_node.cpp",
        "src/control_node.cpp",
        "src/shared_library.cpp",
        "src/tree_node.cpp",
        "src/script_parser.cpp",
        "src/json_export.cpp",
        "src/xml_parsing.cpp",
        "src/actions/test_node.cpp",
        "src/decorators/inverter_node.cpp",
        "src/decorators/repeat_node.cpp",
        "src/decorators/retry_node.cpp",
        "src/decorators/subtree_node.cpp",
        "src/decorators/delay_node.cpp",
        "src/controls/if_then_else_node.cpp",
        "src/controls/fallback_node.cpp",
        "src/controls/parallel_node.cpp",
        "src/controls/reactive_sequence.cpp",
        "src/controls/reactive_fallback.cpp",
        "src/controls/sequence_node.cpp",
        "src/controls/sequence_star_node.cpp",
        "src/controls/switch_node.cpp",
        "src/controls/while_do_else_node.cpp",
        "src/loggers/bt_cout_logger.cpp",
        "src/loggers/bt_file_logger.cpp",
        "src/loggers/bt_minitrace_logger.cpp",
        "src/loggers/bt_observer.cpp",
        "3rdparty/tinyxml2/tinyxml2.cpp",
        "3rdparty/minitrace/minitrace.cpp",
        "src/shared_library_UNIX.cpp",
    ]

    defines = [
        "LEXY_HAS_UNICODE_DATABASE=1",
        "behaviortree_cpp_EXPORTS",
    ]

    configs = [ 
         ":behaviortreecpp_config", 
         ":public_config",
    ] 

    deps = [
         "//third_party/behaviortree:lexy_file",
    ]
    
    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]

    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# libdummy_nodes_dyn.so

config("dummy_nodes_dyn_config"){
    cflags_cc = [
        # 为了编译libbehaviortree_cpp.so原生库中添加的编译器标志
        "-O3", 
        "-DNDEBUG",  
        "-fPIC",    
        "-Wpedantic",   
        "-std=gnu++17",

        # 为了消除shared_library.cpp编译报错添加-fexceptions
        "-fexceptions",
        "-frtti",
        "-Wno-deprecated-volatile",
        "-Wno-unused-lambda-capture",
    ]

    include_dirs = [
         "include",
         "sample_nodes"
    ]

}

ohos_shared_library("dummy_nodes_dyn") {
    
    output_name = "dummy_nodes_dyn" # 可选,模块输出名

    sources = [
        "sample_nodes/dummy_nodes.cpp",
    ]

    defines = [
        "BT_PLUGIN_EXPORT",
        "dummy_nodes_dyn_EXPORTS",
    ]

    configs = [ 
         ":dummy_nodes_dyn_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# libcrossdoor_nodes_dyn.so

config("crossdoor_nodes_dyn_config"){
    cflags_cc = [
        # 为了编译libbehaviortree_cpp.so原生库中添加的编译器标志
        "-O3", 
        "-DNDEBUG",  
        "-fPIC",    
        "-Wpedantic",   
        "-std=gnu++17",

        # 为了消除shared_library.cpp编译报错添加-fexceptions
        "-fexceptions",
        "-frtti",
        "-Wno-deprecated-volatile",
        "-Wno-unused-lambda-capture",
    ]

    include_dirs = [
         "include",
         "sample_nodes"
    ]

}

ohos_shared_library("crossdoor_nodes_dyn") {
    
    output_name = "crossdoor_nodes_dyn" # 可选,模块输出名

    sources = [
        "sample_nodes/crossdoor_nodes.cpp",
    ]

    defines = [
        "BT_PLUGIN_EXPORT",
        "crossdoor_nodes_dyn_EXPORTS",
    ]

    configs = [ 
         ":crossdoor_nodes_dyn_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
    ]
    
    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]

    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# libmovebase_node_dyn.so

config("movebase_node_dyn_config"){
    cflags_cc = [
        # 为了编译libbehaviortree_cpp.so原生库中添加的编译器标志
        "-O3", 
        "-DNDEBUG",  
        "-fPIC",    
        "-Wpedantic",   
        "-std=gnu++17",

        # 为了消除shared_library.cpp编译报错添加-fexceptions
        "-fexceptions",
        "-frtti",
        "-Wno-deprecated-volatile",
        "-Wno-unused-lambda-capture",
    ]

    include_dirs = [
         "include",
         "sample_nodes"
    ]

}

ohos_shared_library("movebase_node_dyn") {
    
    output_name = "movebase_node_dyn" # 可选,模块输出名

    sources = [
        "sample_nodes/movebase_node.cpp",
    ]

    defines = [
        "BT_PLUGIN_EXPORT",
        "movebase_node_dyn_EXPORTS",
    ]

    configs = [ 
         ":movebase_node_dyn_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# t01_build_your_first_tree

config("executable_public_config"){
    cflags_cc = [
        # 为了编译libbehaviortree_cpp.so原生库中添加的编译器标志
        "-O3", 
        "-DNDEBUG",   
        "-Wpedantic",   
        "-std=gnu++17",

        # 为了消除shared_library.cpp编译报错添加-fexceptions
        "-fexceptions",
        "-frtti",
        "-Wno-deprecated-volatile",
        "-Wno-unused-lambda-capture",
    ]

    include_dirs = [
         "include",
         "sample_nodes"
    ]

}

ohos_executable("t01_build_your_first_tree") {
    
    output_name = "t01_build_your_first_tree" # 可选,模块输出名

    sources = [
        "examples/t01_build_your_first_tree.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]
    
    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]

    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# t02_basic_ports

ohos_executable("t02_basic_ports") {
    
    output_name = "t02_basic_ports" # 可选,模块输出名

    sources = [
        "examples/t02_basic_ports.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# t03_generic_ports

ohos_executable("t03_generic_ports") {
    
    output_name = "t03_generic_ports" # 可选,模块输出名

    sources = [
        "examples/t03_generic_ports.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]

    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# t04_reactive_sequence

ohos_executable("t04_reactive_sequence") {
    
    output_name = "t04_reactive_sequence" # 可选,模块输出名

    sources = [
        "examples/t04_reactive_sequence.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# t05_crossdoor

ohos_executable("t05_crossdoor") {
    
    output_name = "t05_crossdoor" # 可选,模块输出名

    sources = [
        "examples/t05_crossdoor.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# t06_subtree_port_remapping

ohos_executable("t06_subtree_port_remapping") {
    
    output_name = "t06_subtree_port_remapping" # 可选,模块输出名

    sources = [
        "examples/t06_subtree_port_remapping.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# t07_load_multiple_xml

ohos_executable("t07_load_multiple_xml") {
    
    output_name = "t07_load_multiple_xml" # 可选,模块输出名

    sources = [
        "examples/t07_load_multiple_xml.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# t08_additional_node_args

ohos_executable("t08_additional_node_args") {
    
    output_name = "t08_additional_node_args" # 可选,模块输出名

    sources = [
        "examples/t08_additional_node_args.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# t09_scripting

ohos_executable("t09_scripting") {
    
    output_name = "t09_scripting" # 可选,模块输出名

    sources = [
        "examples/t09_scripting.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# t10_observer

config("t10_observer_config"){
    cflags_cc = [
        # 为了编译libbehaviortree_cpp.so原生库中添加的编译器标志
        "-O3", 
        "-DNDEBUG",   
        "-Wpedantic",   
        "-std=gnu++17",

        # 为了消除shared_library.cpp编译报错添加-fexceptions
        "-fexceptions",
        "-frtti",
        "-Wno-deprecated-volatile",
        "-Wno-unused-lambda-capture",
        "-Wno-unused-variable",
    ]

    include_dirs = [
         "include",
         "sample_nodes"
    ]

}

ohos_executable("t10_observer") {
    
    output_name = "t10_observer" # 可选,模块输出名

    sources = [
        "examples/t10_observer.cpp",
    ]

    configs = [ 
         ":t10_observer_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# t11_replace_rules

ohos_executable("t11_replace_rules") {
    
    output_name = "t11_replace_rules" # 可选,模块输出名

    sources = [
        "examples/t11_replace_rules.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# ex01_wrap_legacy

ohos_executable("ex01_wrap_legacy") {
    
    output_name = "ex01_wrap_legacy" # 可选,模块输出名

    sources = [
        "examples/ex01_wrap_legacy.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# ex02_runtime_ports

ohos_executable("ex02_runtime_ports") {
    
    output_name = "ex02_runtime_ports" # 可选,模块输出名

    sources = [
        "examples/ex02_runtime_ports.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# ex03_ncurses_manual_selector

ohos_executable("ex03_ncurses_manual_selector") {
    
    output_name = "ex03_ncurses_manual_selector" # 可选,模块输出名

    sources = [
        "examples/ex03_ncurses_manual_selector.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

# ex04_waypoints

ohos_executable("ex04_waypoints") {
    
    output_name = "ex04_waypoints" # 可选,模块输出名

    sources = [
        "examples/ex04_waypoints.cpp",
    ]

    configs = [ 
         ":executable_public_config", 
         ":public_config",
    ] 

    deps = [
        "//third_party/behaviortree:behaviortree_cpp",
        "//third_party/behaviortree:bt_sample_nodes",
    ]

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]
    
    part_name = "behaviortree"

    subsystem_name = "behaviortree"

}

##############################################################################

1.7 对源码进行增量编译,推送编译生成BehaviorTree.CPP的so以及可执行文件到开发板上,验证编译结果

1.7.1 对源码进行增量编译

  • 推荐使用如下命令对对源码进行增量编译,编译生成BehaviorTree.CPP的so以及可执行文件
./build.sh --product-name rk3568 --ccache --build-target=behaviortree --disable-post-build --disable-package-image --gn-args enable_notice_collection=false --gn-args load_test_config=false
  • 默认编译的是32位,添加–target-cpu arm64参数编译64位
--product-name rk3568 :表示编译的产品是rk3568 (润和大禹200)
--build-target=behaviortree :编译子系统behaviortree

以下这些都是加快编译速度的选项
--ccache --build-target=behaviortree --disable-post-build --disable-package-image --gn-args enable_notice_collection=false --gn-args load_test_config=false 

1.7.2 推送编译生成BehaviorTree.CPP的so以及可执行文件到开发板上,验证编译结果

  • so和可执行文件在out\rk3568\behaviortree目录下
    【C++三方库移植】移植BehaviorTree.CPP到OpenHarmony标准系统①-鸿蒙开发者社区

  • liblexy_file.a、libbt_sample_nodes.a等静态库文件在out\rk3568\obj\third_party\behaviortree目录下
    【C++三方库移植】移植BehaviorTree.CPP到OpenHarmony标准系统①-鸿蒙开发者社区

  • 1、通过与ohos版本匹配的hdc_std工具,将编译生成的库以及测试用的可执行文件推送到开发板system/lib (lib64)

hdc shell               
mount -o remount,rw /	    ## 重新加载系统为可读写
chmod 777 t02_basic_ports
./t02_basic_ports

【C++三方库移植】移植BehaviorTree.CPP到OpenHarmony标准系统①-鸿蒙开发者社区

1.8 对源码进行增量编译全量编译,烧录固件验证编译结果。

  • 如果有将编译生成BehaviorTree.CPP的so以及可执行文件打包到固件,随固件烧录到开发板的需求。推荐进行全量编译,执行 ./build.sh --product-name rk3568 --ccache ,然后编译烧录固件到开发板上即可。

  • 编译烧录好固件到开发板后,so文件会在开发板system/lib(64位系统的话在system/lib64),可执行文件会在system/bin

  • hdc shell进入开发板后,在任意目录层级下执行可执行文件都可以
    【C++三方库移植】移植BehaviorTree.CPP到OpenHarmony标准系统①-鸿蒙开发者社区

  • 将编译生成BehaviorTree.CPP的so以及可执行文件打包到固件,在上文third_party/behaviortree/BUILD.gn中已经添加相关代码

    install_enable = true
    
    install_images = [
         "system",
         "ramdisk",
         "updater",
    ]

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
已于2023-7-17 18:49:31修改
5
收藏 3
回复
举报
7条回复
按时间正序
/
按时间倒序
红叶亦知秋
红叶亦知秋

前排关注大佬项目!

1
回复
2023-6-26 17:33:43
唐佐林
唐佐林

不错,多了一个可用的组件!

建议后续考虑一下:

  • 怎么以接口方式提供到app应用层
  • 在app中是否还需要其它关于机器人的组件


2
回复
2023-6-26 18:54:15
离北况归
离北况归 回复了 唐佐林
不错,多了一个可用的组件!建议后续考虑一下:怎么以接口方式提供到app应用层在app中是否还需要其它关于机器人的组件

唐老师,后面继续通过napi框架导出接口到应用层。第二个问题没考虑过,网友之前有过移植这库的需求,我就移植了。

回复
2023-6-26 20:14:33
FlashinMiami
FlashinMiami

很详细的代码讲解

1
回复
2023-6-28 16:12:55
皮皮虾233
皮皮虾233

中间的代码读了好长时间,分享的很完整

1
回复
2023-6-29 11:27:45
只看看不说话
只看看不说话

见证大佬不断突破

1
回复
2023-6-29 18:35:00
喝一大口可乐
喝一大口可乐

我愿称作者为移植先锋

1
回复
2023-7-3 10:18:52
回复
    相关推荐