鸿蒙设备学习|常见编译错误
项目场景:
BearPi-HM_Micro编译源码常见错误
问题描述
问题一:
问题二:
[OHOS ERROR] [1740/2967] ACTION //drivers/adapter/khdf/liteos:build_hc_gen(//build/lite/toolchain:linux_x86_64_ohos_clang)[OHOS ERROR] FAILED: obj/drivers/adapter/khdf/liteos/build_hc_gen_build_ext_components.txt[OHOS ERROR] /usr/bin/python3 ../../../build/lite/build_ext_components.py --path=../../../drivers/framework/tools/hc-gen --command=make --target_dir=/home/bearpi/project/bearpi-hm_micro_small/out/bearpi_hm_micro/bearpi_hm_micro/obj/drivers/adapter/khdf/liteos/build.log --out_dir=/home/bearpi/project/bearpi-hm_micro_small/out/bearpi_hm_micro/bearpi_hm_micro/error.log[OHOS ERROR] CC src/lexer.cpp[OHOS ERROR] make: c++: Command not found[OHOS ERROR] make: * [Makefile:23: build/src/lexer.o] Error 127[OHOS ERROR] you can check build log in /home/bearpi/project/bearpi-hm_micro_small/out/bearpi_hm_micro/bearpi_hm_micro/build.log[OHOS ERROR] command: "/home/bearpi/project/bearpi-hm_micro_small/prebuilts/build-tools/linux-x86/bin/ninja -w dupbuild=warn -C /home/bearpi/project/bearpi-hm_micro_small/out/bearpi_hm_micro/bearpi_hm_micro" failed[OHOS ERROR] return code: 1[OHOS ERROR] execution path: /home/bearpi/project/bearpi-hm_micro_small
问题三:
[OHOS ERROR] [2665/2967] ACTION //kernel/liteos_a:build_kernel_image(//build/lite/toolchain:linux_x86_64_ohos_clang)[OHOS ERROR] FAILED: obj/kernel/liteos_a/build_kernel_image_build_ext_components.txt[OHOS ERROR] /usr/bin/python3 ../../../build/lite/build_ext_components.py --path=/home/bearpi/project/bearpi-hm_micro_small/out/bearpi_hm_micro/bearpi_hm_micro --command=/home/bearpi/project/bearpi-hm_micro_small/prebuilts/clang/ohos/linux-x86_64/llvm/bin/llvm-objcopy\ -O\ binary\ OHOS_Image\ OHOS_Image.bin\ \&\&\ sh\ -c\ \'/home/bearpi/project/bearpi-hm_micro_small/prebuilts/clang/ohos/linux-x86_64/llvm/bin/llvm-objdump\ -t\ OHOS_Image\ \|\ sort\ \>OHOS_Image.sym.sorted\'\ \&\&\ sh\ -c\ \'/home/bearpi/project/bearpi-hm_micro_small/prebuilts/clang/ohos/linux-x86_64/llvm/bin/llvm-objdump\ -d\ OHOS_Image\ \>OHOS_Image.asm\'\ \&\&\ sh\ -c\ \'mkimage\ -A\ arm\ \ -T\ kernel\ -C\ none\ -a\ 0xC0100000\ -e\ 0xC0100000\ -n\ liteos-a\ -d\ OHOS_Image.bin\ OHOS_Image.stm32\'\ --target_dir=/home/bearpi/project/bearpi-hm_micro_small/out/bearpi_hm_micro/bearpi_hm_micro/obj/kernel/liteos_a/build.log --out_dir=/home/bearpi/project/bearpi-hm_micro_small/out/bearpi_hm_micro/bearpi_hm_micro/error.log[OHOS ERROR] sh: mkimage: command not found[OHOS ERROR] cmd:/home/bearpi/project/bearpi-hm_micro_small/prebuilts/clang/ohos/linux-x86_64/llvm/bin/llvm-objcopy -O binary OHOS_Image OHOS_Image.bin[OHOS ERROR] cost time:0:00:00[OHOS ERROR] cmd: sh -c '/home/bearpi/project/bearpi-hm_micro_small/prebuilts/clang/ohos/linux-x86_64/llvm/bin/llvm-objdump -t OHOS_Image | sort >OHOS_Image.sym.sorted'[OHOS ERROR] cost time:0:00:00[OHOS ERROR] cmd: sh -c '/home/bearpi/project/bearpi-hm_micro_small/prebuilts/clang/ohos/linux-x86_64/llvm/bin/llvm-objdump -d OHOS_Image >OHOS_Image.asm'[OHOS ERROR] cost time:0:00:00[OHOS ERROR] you can check build log in /home/bearpi/project/bearpi-hm_micro_small/out/bearpi_hm_micro/bearpi_hm_micro/build.log[OHOS ERROR] command: "/home/bearpi/project/bearpi-hm_micro_small/prebuilts/build-tools/linux-x86/bin/ninja -w dupbuild=warn -C /home/bearpi/project/bearpi-hm_micro_small/out/bearpi_hm_micro/bearpi_hm_micro" failed[OHOS ERROR] return code: 1
问题四:
[OHOS ERROR] [2910/2967] ACTION //applications/BearPi/BearPi-HM_Micro/samples/launcher:launcher_hap(//build/lite/toolchain:linux_x86_64_ohos_clang)[OHOS ERROR] FAILED: obj/applications/BearPi/BearPi-HM_Micro/samples/launcher/launcher_hap_build_log.txt[OHOS ERROR] /usr/bin/python3 ../../../build/lite/hap_pack.py --packing-tool-path /home/bearpi/project/bearpi-hm_micro_small/developtools/packing_tool/jar/hmos_app_packing_tool.jar --mode hap --json-path /home/bearpi/project/bearpi-hm_micro_small/applications/BearPi/BearPi-HM_Micro/samples/launcher/launcher/src/main/config.json --resources-path /home/bearpi/project/bearpi-hm_micro_small/applications/BearPi/BearPi-HM_Micro/samples/launcher/launcher/src/main/resources --ability-so-path /home/bearpi/project/bearpi-hm_micro_small/out/bearpi_hm_micro/bearpi_hm_micro/liblauncher.so --force true --signtool-path /home/bearpi/project/bearpi-hm_micro_small/prebuilts/signcenter/hapsigntool/hapsigntoolv2.jar --privatekey OpenHarmony\ Application\ Release --sign-algo SHA256withECDSA --unsignhap-path /home/bearpi/project/bearpi-hm_micro_small/out/bearpi_hm_micro/bearpi_hm_micro/system/internal/unsigned_launcher.hap --signhap-path /home/bearpi/project/bearpi-hm_micro_small/out/bearpi_hm_micro/bearpi_hm_micro/system/internal/launcher.hap --sign-server rnd-signserver.huawei.com --jks-path /home/bearpi/project/bearpi-hm_micro_small/prebuilts/signcenter/key/OpenHarmony.p12 --cert-path /home/bearpi/project/bearpi-hm_micro_small/prebuilts/signcenter/certificates/OpenHarmonyApplication.pem --sign-by-server False --cert-profile /home/bearpi/project/bearpi-hm_micro_small/applications/BearPi/BearPi-HM_Micro/samples/launcher/cert/com.huawei.launcher_HarmonyAppProvision_release.p7b[OHOS ERROR] Traceback (most recent call last):[OHOS ERROR] File "../../../build/lite/hap_pack.py", line 158, in [OHOS ERROR] sys.exit(main())[OHOS ERROR] File "../../../build/lite/hap_pack.py", line 151, in main[OHOS ERROR] hap_packing(args)[OHOS ERROR] File "../../../build/lite/hap_pack.py", line 85, in hap_packing[OHOS ERROR] cmd_popen(packing_cmd)[OHOS ERROR] File "../../../build/lite/hap_pack.py", line 29, in cmd_popen[OHOS ERROR] proc = subprocess.Popen(cmd)[OHOS ERROR] File "/usr/lib/python3.8/subprocess.py", line 858, in __init__[OHOS ERROR] self._execute_child(args, executable, preexec_fn, close_fds,[OHOS ERROR] File "/usr/lib/python3.8/subprocess.py", line 1704, in _execute_child[OHOS ERROR] raise child_exception_type(errno_num, err_msg, err_filename)[OHOS ERROR] FileNotFoundError: [Errno 2] No such file or directory: 'java'[OHOS ERROR] you can check build log in /home/bearpi/project/bearpi-hm_micro_small/out/bearpi_hm_micro/bearpi_hm_micro/build.log[OHOS ERROR] command: "/home/bearpi/project/bearpi-hm_micro_small/prebuilts/build-tools/linux-x86/bin/ninja -w dupbuild=warn -C /home/bearpi/project/bearpi-hm_micro_small/out/bearpi_hm_micro/bearpi_hm_micro" failed[OHOS ERROR] return code: 1[OHOS ERROR] execution path: /home/bearpi/project/bearpi-hm_micro_small
原因分析:
问题一:
libc++库丢失
问题二:
g++ 库丢失
问题三:
mkimage 工具没找到
问题四:
java版本不对
解决方案:
问题一:
安装库包即可
sudo apt-get install libc6-dev
问题二:
安装库包即可
sudo apt-get install g++
问题三:
或者把 makeimage文件复制到 /usr/bin目录下,修改权限即可
问题四:
sudo apt-get install openjdk-11-jdk
成功编译见下图