-前言

一些常出现的编译报错原因可以先定位一下是否符合:代码没拉全,执行命令步骤漏掉,修改没保存,内存分配不够,代码位置更新编译目录需删掉重新编写

有关编译报错的问题主要分为以下

1.自己修改部分不正确导致报错,

2.环境不兼容等问题

在分析报错时,尤其在大串的报错,一定要先分析精炼出主要原因,报错的根因往往是前几行,或者末尾几列,也可以在exception关键字处分析,对于含糊难以定位的,尤其是一大串的首先就要怀疑必要的环境没配置好,内存分配不足等,

初次搭建编译环境往往成功率不高可参考:OpenHarmony编译环境搭建 (兼容至4.0-Master和主干分支) - 文章 OpenHarmony开发者论坛

出错的主要原因也是一些环境配置没有安装,安装不成功,则可能是版本问题


以下是一些比较典型的例子,欢迎大家继续补充,丰富编译错误相关的解决方法

问题1

4.0版本上

例:Exception: deps validation part_name: 'product_rk3568', target: '//device/board/hihope/rk3568/uart_tool_oh:uart_tool_oh', dep: '//drivers/hdf_core/adapter/uhdf2/platform:libhdf_platform' failed!!!

分析:此处是编译产品rk3568芯片部分的开发板board依赖libhdf_platform组件,原因大概率是将外部依赖当内部依赖(跨部件的依赖为外部,反之为内部)添加外部依赖时格式为 “部件:组件”,而不是路径,这个地方需要注意

解决方案:被依赖的hdf_code部件的组件libhdf_platform,需要将hdf_code加到部件product_rk3568的bundle.json中的dep,将被依赖的build.gn中的deps修改为extern_deps,同时要将hdf_code的bundle.json中的libhdf_platform添加到"bulid标签"的inner_kits形成外部接口供product_rk3568使用

问题2

4.1-release 编译64位系统rk3658 ./build.sh --product-name rk3568 --ccache --target-cpu arm64

例子:[OHOS ERROR] FAILED: obj/foundation/communication/netmanager_base/frameworks/native/netstatsclient/src/proxy/net_stats_manager_if/net_stats_service_proxy.o
[OHOS ERROR] /usr/bin/ccache ../../prebuilts/clang/ohos/linux-x86_64/llvm/bin/clang++ -MMD -MF

分析:当前4.1版本64位的暂无维护,后续将会逐步规范

解决 :可以将参数的格式手动一个个修改为%zu,需要一定时间

问题3

例子:'session_info.h' file not found

分析:说明文件不存在或者配置路径不正确没有办法访问到,

解决:检查路径下是否存在该文件,没有则repo sync -c repo forall -c 'git lfs pull'重新同步一下,若存在文件则分析build各个bundle.josn build.gn是否指向该路径 ,配置是否正确 (一般是由于改动引起的需要仔细按引用路径排查那个地方找不到了)

问题4

例子:

[OHOS INFO]
[OHOS INFO] ERROR at //build/templates/cxx/cxx.gni:1190:38 (//build/toolchain/linux:clang_x64): Could not read file.
[OHOS INFO] external_deps_info = read_file(external_deps_temp_file, "json")
[OHOS INFO] ^----------------------

分析:依赖的问题都是类似的,找到所需依赖的文件,并将依赖引用到所需地方

解决:如果部件需要依赖其他子系统的组件而config中没有,则需要在config.json中添加子系统

问题5

FAILED: load BTF from vmlinux: Unknown error -22make[2]: *** [/home/hwl/OpenHarmony_master/out/kernel/src_tmp/linux-5.10/Makefile:1225: vmlinux] Error 255

分析:日志的报错远比截取的长,而且无法定位分析,最终解决是因为内存分配不足,所以一定要仔细

问题6

[OHOS ERROR] /usr/bin/env ../../foundation/arkui/ace_engine/build/tools/build_js.py ../../foundation/ability/ability_runtime/services/dialog_ui/dialog_anr/js obj/foundation/ability/ability_runtime/services/dialog_ui/dialog_anr/js ../../prebuilts/build-tools/common/nodejs/node-v12.18.4-linux-x64/bin ../../developtools/ace_js2bundle ../../interface ../../third_party/parse5 ../../third_party/weex-loader [OHOS ERROR] internal/modules/cjs/loader.js:968 [OHOS ERROR] throw err; [OHOS ERROR] ^ [OHOS ERROR] [OHOS ERROR] Error: Cannot find module '../lib/utils/unsupported.js'

分析:error找不到某module下的一个js,同第三问,重新确认一下文件是否存在,查看配置路径是否正确

解决:检查路径下是否存在该文件,没有则repo sync -c repo forall -c 'git lfs pull'重新同步一下,若存在文件则分析build各个bundle.josn build.gn是否指向该路径 ,配置是否正确

问题7

例子:Openharmony_rk3568-4.0-release 编译报错,求解

操作步骤:

​ \OpenHarmony-4.0-release\productdefine\common\inherit\rich.json中的锁屏的screenlock_mgr删掉

ERROR at //build/templates/cxx/cxx.gni:870:26: Script returned non-zero exit code.

handler_result = exec_script(external_deps_script, arguments, "string")

^----------

Current dir: /home/tf/OpenHarmony-4.0-release/out/rk3568/

Command: /usr/bin/env /home/tf/OpenHarmony-4.0-release/build/templates/common/external_deps_handler.py --external-deps ability_runtime:ability_manager c_utils:utils graphic_2d:librender_service_client hilog:libhilog ipc:ipc_single screenlock_mgr:screenlock_server --parts-src-flag-file build_configs/parts_src_flag.json --external-deps-temp-file gen/foundation/window/window_manager/window_scene/session_manager_service/window_manager__session_manager_service_external_deps_temp.json --sdk-base-dir ../../sdk/ohos-arm --sdk-dir-name sdk/ohos-arm --current-toolchain //build/toolchain/ohos:ohos_clang_arm --innerkits-adapter-info-file ../../build/ohos/inner_kits_adapter.json --component-override-map /home/tf/OpenHarmony-4.0-release/out/rk3568/build_configs/component_override_map.json

Returned 1 and printed out:

file '../../sdk/ohos-arm/screenlock_mgr/sdk_info.json' doesn't exist.

stderr:

Traceback (most recent call last):

File "/home/tf/OpenHarmony-4.0-release/build/templates/common/external_deps_handler.py", line 259, in

sys.exit(main())

File "/home/tf/OpenHarmony-4.0-release/build/templates/common/external_deps_handler.py", line 225, in main

sdk_module_info, adapted_ok = _get_external_module_from_sdk(

File "/home/tf/OpenHarmony-4.0-release/build/templates/common/external_deps_handler.py", line 74, in _get_external_module_from_sdk

raise Exception("part '{}' doesn't exist in sdk modules.".format(

Exception: part 'screenlock_mgr' doesn't exist in sdk modules.

See //foundation/window/window_manager/window_scene/session_manager_service/BUILD.gn:24:1: whence it was called.

ohos_shared_library("session_manager_service") {

分析:build目录下的没有改动通常不会报错,所以仍要往下看,找关键字Exception: part 'screenlock_mgr' doesn't exist in sdk modules.说明是该文件删掉后的配置没有修改好,仍有地方依赖着该文件而在寻找它,

解决:最后一行可以推测出编译时session_manager_service/BUILD.gn这个里面有配置外部依赖screenlock_mgr组件就会报找不到,所以我们需要删掉这个依赖配置的关系

问题8

修改了skia的一个选项,并编译

[OHOS INFO] ERROR at //build/templates/cxx/cxx.gni:874:26: Script returned non-zero exit code.
[OHOS INFO] handler_result = exec_script(external_deps_script, arguments, "string")
[OHOS INFO] ^----------
[OHOS INFO] Current dir: /home/zxy/work/openharmony/ohos4-1/out/a33/
[OHOS INFO] Command: /usr/bin/env /home/zxy/work/openharmony/ohos4-1/build/templates/common/external_deps_handler.py --external-deps hilog:libhilog hitrace_native:hitrace_meter --parts-src-flag-file build_configs/parts_src_flag.json --external-deps-temp-file gen/third_party/skia/skia__skia_canvaskit_external_deps_temp.json --sdk-base-dir ../../sdk/ohos-arm --sdk-dir-name sdk/ohos-arm --current-toolchain //build/toolchain/ohos:ohos_clang_arm --innerkits-adapter-info-file ../../build/ohos/inner_kits_adapter.json --component-override-map /home/zxy/work/openharmony/ohos4-1/out/a33/build_configs/component_override_map.json
[OHOS INFO] Returned 1 and printed out:
[OHOS INFO]
[OHOS INFO] file '../../sdk/ohos-arm/hitrace_native/sdk_info.json' doesn't exist.
[OHOS INFO]
[OHOS INFO] stderr:
[OHOS INFO]
[OHOS INFO] Traceback (most recent call last):
[OHOS INFO] File "/home/zxy/work/openharmony/ohos4-1/build/templates/common/external_deps_handler.py", line 262, in
[OHOS INFO] sys.exit(main())
[OHOS INFO] File "/home/zxy/work/openharmony/ohos4-1/build/templates/common/external_deps_handler.py", line 229, in main
[OHOS INFO] sdk_module_info, adapted_ok = _get_external_module_from_sdk(
[OHOS INFO] File "/home/zxy/work/openharmony/ohos4-1/build/templates/common/external_deps_handler.py", line 74, in _get_external_module_from_sdk
[OHOS INFO] raise Exception("part '{}' doesn't exist in sdk modules.".format(
[OHOS INFO] Exception: part 'hitrace_native' doesn't exist in sdk modules.
[OHOS INFO]
[OHOS INFO] See //third_party/skia/BUILD.gn:1652:3: whence it was called.
[OHOS INFO] ohos_shared_library("skia_canvaskit") {
[OHOS INFO] ^--------------------------------------
[OHOS INFO] See //foundation/arkui/ace_engine/interfaces/inner_api/drawable_descriptor/BUILD.gn:60:15: which caused the file to be included.
[OHOS INFO] deps += [ "$skia_root_new:skia_ohos" ]
[OHOS INFO] ^-------------------------
[OHOS INFO] { }
[OHOS INFO] cmd ['/home/zxy/work/openharmony/ohos4-1/third_party/openssl/make_openssl_build_all_generated.sh', '/home/zxy/work/openharmony/ohos4-1/third_party/openssl', '/home/zxy/work/openharmony/ohos4-1/out/a33/obj/third_party/openssl/build_all_generated', 'linux-armv4'] start
[OHOS INFO] result.returncode = 0
[OHOS INFO] result.stdout = /home/zxy/work/openharmony/ohos4-1/out/a33
[OHOS INFO] ~/work/openharmony/ohos4-1/out/a33/obj/third_party/openssl/build_all_generated/linux-armv4 ~/work/openharmony/ohos4-1/out/a33
[OHOS INFO] /home/zxy/work/openharmony/ohos4-1/third_party/openssl/Configure linux-armv4 no-shared no-module
[OHOS INFO] Configuring OpenSSL version 3.0.7 for target linux-armv4
[OHOS INFO] Using os-specific seed configuration
[OHOS INFO] Created configdata.pm
[OHOS INFO] Running configdata.pm
[OHOS INFO] Created Makefile.in
[OHOS INFO] Created Makefile
[OHOS INFO] Created include/openssl/configuration.h

分析:build报错通常是表面编译不正确,继续寻找原因查找关键字 Exception: part 'hitrace_native' doesn't exist in sdk modules快速定位到exception 说明hitrace_native没有配置到模块里面,

解决:如果没有了解配置规则还是难发现的,对于部件外的依赖,deps += [ "$skia_root_new:skia_ohos" ],去gn里面看应该修改为external_deps += [ "hitrace:hitrace_meter" ]

问题9

OH 4.0 Release full sdk编译报错

img

分析:此类无法准确定位到某个地方,可以考虑环境配置,内存不够等问题,需重新检查一下环境,SDK构建失败一般都是Ubuntu的包没有安装全导致的

解决:执行sudo apt-get install libgl1-mesa-dev libglu1-mesa-dev试试,编译环境可参考:https://forums.openharmony.cn/forum.php?mod=viewthread&tid=897&page=1#pid2144&login=from_csdn “安装必要的库和工具

问题10

系统是lite,编译日志系统hilogcat和apphilogcat都能正常编译出来,但是hiview没有编译出来,请问缺少什么依赖吗?

config.json配置如下:

{
"subsystem": "hiviewdfx",
"components": [
{ "component": "hilog_featured_lite", "features":[] },
{ "component": "hidumper_lite", "features":[] }
]
}

一直无法编译出hiview

分析:配置的config没错,没有见具体报错日志,分析是配置不对

解决:配置正确,若L是inux内核的OH系统 ,hidumper 只支持 Liteos_A/M 内核系统,不支持 Linux内核的系统。

问题11

编译报错Exception: find component ipc failed

img

分析:看出congfig中可能并没有或者配置错了ipc的内容,

解决:将ipc的正确配置加入congfig.json中,可以参考官网配置产品rk3568,vendor产品目录config.josn,相关部件的bundle.json,组件的gn中都要正确配置

问题12

patch: ....too may open file

img

分析:打开的文件过多,超出了系统的限制,

解决:设置ulimit -n 1000000 若不允许这个值则重启后再试试,或者调小一点取值

问题13

鸿蒙系统使用gcc工具链(board_toolchain_type = "gcc")编译完musl库后编译其它C++文件都报找不到头文件

[OHOS ERROR] In file included from ../../../base/hiviewdfx/hilog_lite/frameworks/js/builtin/src/hilog_realloc.cpp:16:
[OHOS ERROR] ../../../base/hiviewdfx/hilog_lite/frameworks/js/builtin/include/hilog_realloc.h:19:10: fatal error: cstdlib: No such file or directory
[OHOS ERROR] #include
[OHOS ERROR] ^~~~~~~~~
[OHOS ERROR] compilation terminated.
[OHOS ERROR] [51/4006] gcc CXX obj/base/global/i18n_lite/frameworks/i18n/src/libglobal_i18n.date_time_format.o
[OHOS ERROR] FAILED: obj/base/global/i18n_lite/frameworks/i18n/src/libglobal_i18n.date_time_format.o

分析:无法找到相关的头文件,说明配置路径不对,或者编译选项不正确导致,对于那些编译时生成的文件则需要分析配置gn中的include是否包含或导入的是否包含

解决:可能是其他的c++文件没有正确配置导致,且当前OH并没有移植gcc编译工具链的案例,这个问题需要确保你的编译选项正确设置,以便编译器能够正确地找到头文件和库文件,例如-l 包含的头文件路径和-o 链接库

问题14

编译OpenHarmony3.2Release失败,编译完成 后,报在ninja2trace.py文件中执行int()函数时,参数错误的问题

img

分析:ninjia2trace.py中,执行int(start)时整形转换报错,start值未识别为整形数

解决:这个文件里都是一些编译对象的记录,只能说这行写入失败了,可以删除该文件,尝试重新编一下试试,或者修改下脚本,通过类型判断或try catch处理下

问题15

在使用ohos_shared_library编译动态链接库的时候,希望屏蔽掉unused-variable和unused-function的报错,在BUILD.gn中添加了cflags = ["-Wno-unused-variable","-Wno-unused-function"] 但编译时仍有报错,请问应该如何修改?

img

分析:当试图忽略掉位运算报错时,发现没有作用,更改参数仍然不行,"-Wno-unused-variable","-Wno-unused-function",把"-Wall"也加上试试,是否是参数没生效

解决:如果还是不行尝试使用cflag_c,cflag_cc,可能是被别的参数影响到

问题16

ninja: error: '../../drivers/peripheral/camera/vdi_base/v4l2/src/camera_dump.cpp', needed by 'obj/drivers/peripheral/camera/vdi_base/v4l2/src/camera_host_vdi_impl_1.0/camera_dump.o', missing and no known rule to make it

分析: needed by 说明依赖的这个文件没有找到,若需要则在增加该文件,不需要则直接在配置中删掉这层依赖,missing and no known rule to make it说明没有遵守相应的白名单机制,可以去官网了解如何遵守配置规则

问题17

添加cpp报错

系统版本:4.0 release

将foundation/graphic/graphic_2d/rosen/samples/composer/hello_composer.cpp添加到编译流程中,出现编译报错。求助这个报错应如何处理

[OHOS ERROR] g_receiver = new VSyncReceiver(vsyncConnection, mainThreadHandler_);
[OHOS ERROR] ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[OHOS ERROR] ../../foundation/graphic/graphic_2d/interfaces/inner_api/composer/vsync_receiver.h:66:5: note: candidate constructor not viable: no known conversion from 'std::shared_ptr<OHOS::AppExecFwk::EventHandler>' to 'const sptr<OHOS::IRemoteObject>' for 2nd argument
[OHOS ERROR] VSyncReceiver(const sptr<IVSyncConnection>& conn,
[OHOS ERROR] ^
[OHOS ERROR] ../../foundation/graphic/graphic_2d/interfaces/inner_api/composer/vsync_receiver.h:72:5: note: candidate constructor not viable: requires 1 argument, but 2 were provided
[OHOS ERROR] VSyncReceiver(const VSyncReceiver &) = delete;
[OHOS ERROR] ^
[OHOS ERROR] ../../foundation/graphic/graphic_2d/rosen/samples/composer/hello_composer.cpp:467:14: error: variable 'clientCount' set but not used [-Werror,-Wunused-but-set-variable]
[OHOS ERROR] uint32_t clientCount = 0;
[OHOS ERROR] ^
[OHOS ERROR] 2 errors generated.
[OHOS ERROR] Traceback (most recent call last):
[OHOS ERROR] File "/home/openharmony/4.0_Release/build/hb/services/ninja.py", line 49, in _execute_ninja_cmd
[OHOS ERROR] SystemUtil.exec_command(
[OHOS ERROR] File "/home/openharmony/4.0_Release/build/hb/util/system_util.py", line 63, in exec_command
[OHOS ERROR] raise OHOSException(
[OHOS ERROR] exceptions.ohos_exception.OHOSException: Please check build log in /home/openharmony/4.0_Release/out/rk3588/build.log
[OHOS ERROR]
[OHOS ERROR] During handling of the above exception, another exception occu

分析:第一个构造函数不匹配似乎是参数问题,看看mainThreadHandler_是不是缺省的第二个参数类型,后面clientCount 是定义了但没使用的报错,不用就先注掉

-为删除该行 +为添加 下为build.gn中删除添加的修改内容

修改:part1: diff --git a/rosen/samples/composer/BUILD.gn b/rosen/samples/composer/BUILD.gn index df741b676..ad09a4de8 100644 --- a/rosen/samples/composer/BUILD.gn +++ b/rosen/samples/composer/BUILD.gn @@ -57,6 +57,7 (列号行号)@@ ohos_executable("hello_composer") { external_deps = [ "eventhandler:libeventhandler", "hilog:libhilog", + "c_utils:utils", ] part_name = "graphic_2d"

​ part2: diff --git a/rosen/samples/composer/hello_composer.cpp b/rosen/samples/composer/hello_composer.cpp --- a/rosen/samples/composer/hello_composer.cpp +++ b/rosen/samples/composer/hello_composer.cpp @@ -74,7 +74,7 @@ void HelloComposer::Run(const std::vector &runArgs) - g_receiver = new VSyncReceiver(vsyncConnection, mainThreadHandler_); + g_receiver = new VSyncReceiver(vsyncConnection, nullptr, mainThreadHandler_);

​ part3: diff --git a/rosen/samples/composer/hello_composer.cpp b/rosen/samples/composer/hello_composer.cpp --- a/rosen/samples/composer/hello_composer.cpp +++ b/rosen/samples/composer/hello_composer.cpp @@ -464,9 +464,10 @@ void HelloComposer::DoPrepareCompleted(sptr surface, - uint32_t clientCount = 0; + uint32_t clientCount [[gnu::unused]]; bool hasClient = false; const std::vector &layers = param.layers; + clientCount = 0;

问题18

添加ability子系统lite相关的组件编译wms_server报错

针对display_gfx.so、display_layer.so、display_gralloc.so 找不到对应的依赖

[OHOS ERROR] /home/lz_oh/l00804910/buildtools/RTOS5.10/micro/opt/RTOS/208.5.0/arm32A9le_5.10_ek_micro/gnu/bin/../lib/gcc/arm-linux-musleabi/7.3.0/../../../../arm-linux-musleabi/bin/ld: ./libdisplay_layer.so: undefined reference to `HI_MPI_HDMI_DeInit'
[OHOS ERROR] /home/lz_oh/l00804910/buildtools/RTOS5.10/micro/opt/RTOS/208.5.0/arm32A9le_5.10_ek_micro/gnu/bin/../lib/gcc/arm-linux-musleabi/7.3.0/../../../../arm-linux-musleabi/bin/ld: ./libdisplay_gfx.so: undefined reference to `HI_TDE2_BeginJob'
[OHOS ERROR] /home/lz_oh/l00804910/buildtools/RTOS5.10/micro/opt/RTOS/208.5.0/arm32A9le_5.10_ek_micro/gnu/bin/../lib/gcc/arm-linux-musleabi/7.3.0/../../../../arm-linux-musleabi/bin/ld: ./libdisplay_layer.so: undefined reference to `HI_MPI_HDMI_SetAttr'
[OHOS ERROR] /home/lz_oh/l00804910/buildtools/RTOS5.10/micro/opt/RTOS/208.5.0/arm32A9le_5.10_ek_micro/gnu/bin/../lib/gcc/arm-linux-musleabi/7.3.0/../../../../arm-linux-musleabi/bin/ld: ./libdisplay_layer.so: undefined reference to `HI_MPI_HDMI_GetAttr'等

解决:libdisplay_layer.so这几个好像是要先编出来再复制到对应目录下,先把libdisplay_gfx.so 使用gcc编译出来

相关文件下载
编译报错总结.pdf
384.20 KB
下载
Logo

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

更多推荐