Harmony OS C++实战

开发步骤
  1. 安装devcostudio打开
  2. File->New->CreateProject->Native C++
bash 复制代码
cd src/main && git clone https://github.com/freetype/freetype && mv freetype/* cpp/
  1. 多平台配置 新增build-profile.json5下abiFilters,支持多平台

    "externalNativeOptions": {

    "path": "./src/main/cpp/CMakeLists.txt",

    "arguments": "",

    "cppFlags": "",

    "abiFilters": [

    "x86_64",

    "arm64-v8a"

    ]

    }

  2. 点击锤子🔨make module生成,右上角圆点切换debug|release。输出文件在build\default\outputs\default\*.hap,解压有ABI对应的.so文件。
  3. ts或其它库调用使用时,需在src同级目录下新建libs文件夹,拷贝abiFilters所有文件夹到libs下。
.so cmake配置
cpp 复制代码
cmake_minimum_required(VERSION 3.5.0)
project(NativeFileAccess)

set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})

if(DEFINED PACKAGE_FIND_FILE)
    include(${PACKAGE_FIND_FILE})
endif()

include_directories(${NATIVERENDER_ROOT_PATH}
                    ${NATIVERENDER_ROOT_PATH}/include)
link_directories(${NATIVERENDER_ROOT_PATH}/../../../libs/${OHOS_ARCH})

add_library(file_access SHARED FileAccessMethods.cpp)

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
    set_property(TARGET file_access PROPERTY IMPORTED_LOCATION ${NATIVERENDER_ROOT_PATH}/libs/${OHOS_ARCH}/libfreetyped.so)
else()
    set_property(TARGET file_access PROPERTY IMPORTED_LOCATION ${NATIVERENDER_ROOT_PATH}/libs/${OHOS_ARCH}/libfreetype.so)
endif ()

set_property(TARGET file_access PROPERTY IMPORTED_LOCATION ${NATIVERENDER_ROOT_PATH}/libs/${OHOS_ARCH}/libc++_shared.so)
target_link_libraries(file_access PUBLIC libace_napi.z.so libhilog_ndk.z.so librawfile.z.so libc++_shared.so)
target_link_libraries(file_access PUBLIC debug libfreetyped.so optimized libfreetype.so)
库依赖查看

readelf -d lib.so

:so.x.x不支持,需用.so加载

参考

https://developer.huawei.com/consumer/cn/doc/harmonyos-faqs/faqs-compiling-and-building-86

https://developer.huawei.com/consumer/cn/doc/harmonyos-faqs/faqs-access-control-14

https://gitee.com/openharmony-sig/tpc_c_cplusplus.git

https://github.com/AiMiDi/icu-cmake

https://developer.huawei.com/consumer/cn/doc/harmonyos-faqs/faqs-ndk-72

https://gitee.com/harmonyos_samples/NativeFileAccess

https://gitee.com/harmonyos_samples/hiaifoundationkit-samplecode-clientdemo-cpp

https://gitee.com/harmonyos_samples/native-multi-threads


创作不易,小小的支持一下吧!

相关推荐
南行*7 分钟前
C语言Linux环境编程
linux·c语言·开发语言·网络安全
Morwit9 分钟前
Qt qml创建c++类的单例对象
开发语言·c++·qt
June`9 分钟前
IO模型全解析:从阻塞到异步(高并发的reactor模型)
linux·服务器·网络·c++
古城小栈12 分钟前
Rust 已经自举,却仍需GNU与MSVC工具链的缘由
开发语言·rust
YxVoyager15 分钟前
Qt C++ :QRegularExpression 正则表达式使用详解
c++·qt·正则表达式
jarreyer16 分钟前
数据项目分析标准化流程
开发语言·python·机器学习
闻缺陷则喜何志丹17 分钟前
【回文 字符串】3677 统计二进制回文数字的数目|2223
c++·算法·字符串·力扣·回文
李余博睿(新疆)19 分钟前
c++分治算法
c++
你怎么知道我是队长19 分钟前
C语言---printf函数使用详细说明
c语言·开发语言
liulilittle21 分钟前
俄罗斯访问欧洲国际线路优化
开发语言·网络·信息与通信·ip·通信·俄罗斯·莫斯科