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


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

相关推荐
似水明俊德3 小时前
02-C#.Net-反射-面试题
开发语言·面试·职场和发展·c#·.net
Thera7774 小时前
C++ 高性能时间轮定时器:从单例设计到 Linux timerfd 深度优化
linux·开发语言·c++
炘爚4 小时前
C语言(文件操作)
c语言·开发语言
阿蒙Amon5 小时前
C#常用类库-详解SerialPort
开发语言·c#
凸头5 小时前
CompletableFuture 与 Future 对比与实战示例
java·开发语言
wuqingshun3141595 小时前
线程安全需要保证几个基本特征
java·开发语言·jvm
君义_noip5 小时前
信息学奥赛一本通 1952:【10NOIP普及组】三国游戏 | 洛谷 P1199 [NOIP 2010 普及组] 三国游戏
c++·信息学奥赛·csp-s
Moksha2625 小时前
5G、VoNR基本概念
开发语言·5g·php
jzlhll1235 小时前
kotlin Flow first() last()总结
开发语言·前端·kotlin
W.D.小糊涂5 小时前
gpu服务器安装windows+ubuntu24.04双系统
c语言·开发语言·数据库