1、在CMakeLists.txt中加上

# 增加hiloglib库引用
find_library(
    # Sets the name of the path variable.
    hilog-lib
    # Specifies the name of the NDK library that
    # you want CMake to locate.
    hilog_ndk.z
)

2、增加hiloglib库链接

target_link_libraries(entry PUBLIC ${hilog-lib} libace_napi.z.so)

3、在C++中加上头文件

#include <hilog/log.h>

4、增加打印语句

OH_LOG_Print(LOG_APP, LOG_DEBUG, 0xFF00, "Modbus", "----Read registers failed:%{public}d", regs);

详细操作可以参考浅谈OpenHarmony4.0的NDK开发 - 文章 OpenHarmony开发者论坛

Logo

社区规范:仅讨论OpenHarmony相关问题。

更多推荐