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


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

相关推荐
yijianace3 小时前
Python爬虫实战:BooksToScrape 多线程爬取与图片下载
开发语言·爬虫·python
凡人叶枫3 小时前
Effective C++ 条款15:在资源管理类中提供对原始资源的访问
linux·开发语言·c++·stm32·单片机
swordbob3 小时前
Spring Boot 2.0 改 CGLIB 后,接口实现是否有影响
java·开发语言·spring
郝学胜-神的一滴3 小时前
中级OpenGL教程 009:用环境光告别模型死黑
前端·c++·unity·godot·图形渲染·opengl·unreal
AI人工智能+电脑小能手3 小时前
【大白话说Java面试题 第106题】【并发篇】第6题:synchronized 锁的锁对象可以是什么?
java·开发语言·面试
质造者3 小时前
Python 本地 RAG 实战 | Ollama+ChromaDB 实现 PDF 离线智能问答
开发语言·python·pdf·大模型·rag
slandarer3 小时前
MATLAB | 韦恩图的高阶版: UpSet图 更新升级啦!
开发语言·matlab
Leweslyh3 小时前
3GPP TS 28.312 意图驱动管理服务 — 极详细通俗解读
开发语言·php
swordbob3 小时前
Spring事务失效的场景
java·开发语言·spring
cccyi73 小时前
C++ 面试题整理
c++·面试