在ubuntu-21.10上编译OHOS 3.1的坑 原创

liangkz_梁开祝
发布于 2022-5-17 19:18
浏览
3收藏

  这两天我基于:VMware® Workstation 16 Player(16.2.1 build-18811642)+ ubuntu-21.10-desktop-amd64,重新搭建了一个编译环境,按官方指导给出的步骤安装完软件后,拉取一个干净的最新的3.1 Release代码回来。
  编译轻量系统、小型系统没问题,直接编译RK3568项目,出现了一些编译异常,参考度娘的资料,做了一些修改后编译成功。我看了一下master分支代码,估计也会有类似问题,现把几个小坑放上来给大家做一下参考【++奇怪的是,大家都没有遇到这些异常吗?难道是我的编译环境还有些地方没配好??++】。

1. error: ‘size_t’ has not been declared

Line 351: /home/ohos/Ohos/A_LTS31/drivers/framework/tools/hdi-gen/util/string.h:23:32: error: ‘size_t’ has not been declared
......
Line 365: /home/ohos/Ohos/A_LTS31/drivers/framework/tools/hdi-gen/ast/ast_namespace.h:36:40: error: ‘size_t’ has not been declared
......
Line 392: /home/ohos/Ohos/A_LTS31/drivers/framework/tools/hdi-gen/util/string_builder.h:31:15: error: ‘size_t’ has not been declared
......
/home/ohos/Ohos/A_LTS31/drivers/framework/tools/hdi-gen/util/string_builder.cpp:27:9: error: ‘position_’ was not declared in this scope
   27 |     if (position_ + 1 >= capacity_) {
      |         ^~~~~~~~~
/home/ohos/Ohos/A_LTS31/drivers/framework/tools/hdi-gen/util/string_builder.cpp:27:26: error: ‘capacity_’ was not declared in this scope
   27 |     if (position_ + 1 >= capacity_) {
      |                          ^~~~~~~~~
/home/ohos/Ohos/A_LTS31/drivers/framework/tools/hdi-gen/util/string_builder.cpp:33:13: error: ‘position_’ was not declared in this scope
   33 |     buffer_[position_] = c;
      |             ^~~~~~~~~

编译过程会出现大量的(过百条)上述异常。
度娘找到:Linux下编译C++出现的错误

据说这是因为在Linux系统下 g++ 没有C++的size_t
方案:需要在需要到size_t的文件中加入头文件 stdlib.h问题就解决了

因此,我在 //drivers/framework/tools/hdi-gen/util/string.h 文件头部增加一句:

#include <stdlib.h>

解决掉大部分的编译异常。

2. error: ‘islower’ was not declared in this scope

/home/ohos/Ohos/A_LTS31/drivers/framework/tools/hdi-gen/codegen/java_code_emitter.cpp:38:27: error: ‘islower’ was not declared in this scope
   38 |     if (name.IsEmpty() || islower(name[0])) {
      |                           ^~~~~~~
/home/ohos/Ohos/A_LTS31/drivers/framework/tools/hdi-gen/codegen/java_code_emitter.cpp:41:35: error: ‘tolower’ was not declared in this scope
   41 |     return String::Format("%c%s", tolower(name[0]), name.Substring(1).string());
      |                                   ^~~~~~~

继续编译会出现几条上述异常,参考第1条的处理办法,在//drivers/framework/tools/hdi-gen/codegen/java_code_emitter.h 文件头部增加一句:

#include <ctype.h>

可以解决此类异常。

3.error: no member named ‘optional’ in namespace ‘std’

../../developtools/hiperf/include/callstack.h:102:67: error: no member named 'optional' in namespace 'std'
    using dsoUnwDynInfoMap = std::unordered_map<std::string, std::optional<unw_dyn_info_t>>;
                                                             ~~~~~^
../../developtools/hiperf/include/callstack.h:102:76: error: unexpected type name 'unw_dyn_info_t': expected expression
    using dsoUnwDynInfoMap = std::unordered_map<std::string, std::optional<unw_dyn_info_t>>;
                                                                           ^
../../developtools/hiperf/include/callstack.h:103:31: error: use of undeclared identifier 'dsoUnwDynInfoMap'
    std::unordered_map<pid_t, dsoUnwDynInfoMap> unwindDynInfoMap_;
                              ^

继续编译会出现几条上述异常,在 //developtools/hiperf/include/callstack.h 文件头部增加一句:

#include <optional>

可以解决此类异常。

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
已于2022-5-17 19:18:25修改
4
收藏 3
回复
举报
15条回复
按时间正序
/
按时间倒序
mb62845231a174e
mb62845231a174e

昨天新拉master代码直接编译3568没出现error啊

1
回复
2022-5-18 09:57:00
mb62845231a174e
mb62845231a174e 回复了 mb62845231a174e
昨天新拉master代码直接编译3568没出现error啊

ubuntu-21.10-desktop-amd64有可能是这个arm64上编译会报错

1
回复
2022-5-18 10:03:22
liangkz_梁开祝
liangkz_梁开祝 回复了 mb62845231a174e
ubuntu-21.10-desktop-amd64有可能是这个arm64上编译会报错

那有可能真是Ubuntu版本更新造成的一些兼容性问题~~

所以,OHOS的开发环境搭建,还真的是入门的绊脚石~~

1
回复
2022-5-18 10:46:58
陈浩南xxx
陈浩南xxx 回复了 liangkz_梁开祝
那有可能真是Ubuntu版本更新造成的一些兼容性问题~~ 所以,OHOS的开发环境搭建,还真的是入门的绊脚石~~

确实是一堆报错, 新手,根本不知道如何解决;

 

回复
2022-6-10 17:31:07
liangkz_梁开祝
liangkz_梁开祝 回复了 陈浩南xxx
确实是一堆报错, 新手,根本不知道如何解决;

新手还是建议严格按照官方给出的要求来做,Ubuntu就用20.04,不要用其他版本就可以了。

其次是多问度娘,我们遇到的问题,别人都肯定已经踩过坑了,在网上找不到解决办法,那么恭喜你,你可以为OpenHarmony做贡献了。

回复
2022-6-11 08:50:30
陈浩南xxx
陈浩南xxx 回复了 liangkz_梁开祝
新手还是建议严格按照官方给出的要求来做,Ubuntu就用20.04,不要用其他版本就可以了。 其次是多问度娘,我们遇到的问题,别人都肯定已经踩过坑了,在网上找不到解决办法,那么恭喜你,你可以为OpenHarmony做贡献了。

我选择入门到放弃;

回复
2022-6-13 11:37:49
陈浩南xxx
陈浩南xxx

[OHOS INFO] [297/2187] ACTION //ark/ts2abc/ts2panda:npm_run_build(//build/toolchain/linux:clang_x64)
[OHOS ERROR] [295/2187] ACTION //foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/medialibrary_data_ability:medialibrary_dynamic_hap(//build/toolchain/ohos:ohos_clang_arm)
[OHOS ERROR] FAILED: obj/foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/medialibrary_data_ability/Media_Library.hap 
[OHOS ERROR] /usr/bin/env ../../build/scripts/hapbuilder.py --depfile gen/foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/medialibrary_data_ability/medialibrary_dynamic_hap.d --hap-profile ../../foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/medialibrary_data_ability/config.json --hapsigner ../../prebuilts/signcenter/hapsigntool/hapsigntoolv2.jar --hap-packing-tool ../../developtools/packing_tool/jar/app_packing_tool.jar --hap-path obj/foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/medialibrary_data_ability/Media_Library.hap --packaged-resources obj/foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/medialibrary_data_ability/medialibrary_dynamic_hap/resources.zip --packaged-js-assets obj/foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/medialibrary_data_ability/medialibrary_dynamic_hap/js_assets.zip --assets=@FileArg\(gen/foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/medialibrary_data_ability/medialibrary_dynamic_hap.metadata:root:assets\) --private-key-path OpenHarmony\ Application\ Release --sign-algo SHA256withECDSA --certificate-profile ../../foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/signature/medialib.p7b --keyalias 123456 --keystore-path ../../prebuilts/signcenter/key/OpenHarmony.p12 --keystorepasswd 123456 --certificate-file ../../prebuilts/signcenter/certificates/OpenHarmonyApplication.pem --dso=@FileArg\(obj/foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/medialibrary_data_ability/medialibrary_data_ability_module_info.json:source\)
[OHOS ERROR] Traceback (most recent call last):
[OHOS ERROR]   File "../../build/scripts/hapbuilder.py", line 200, in <module>
[OHOS ERROR]     sys.exit(main(sys.argv[1:]))
[OHOS ERROR]   File "../../build/scripts/hapbuilder.py", line 185, in main
[OHOS ERROR]     build_utils.call_and_write_depfile_if_stale(
[OHOS ERROR]   File "/home/pengweijie/openharmony/build/scripts/util/build_utils.py", line 709, in call_and_write_depfile_if_stale
[OHOS ERROR]     md5_check.call_and_record_if_stale(on_stale_md5,
[OHOS ERROR]   File "/home/pengweijie/openharmony/build/scripts/util/md5_check.py", line 121, in call_and_record_if_stale
[OHOS ERROR]     function(*args)
[OHOS ERROR]   File "/home/pengweijie/openharmony/build/scripts/util/build_utils.py", line 699, in on_stale_md5
[OHOS ERROR]     function(*args)
[OHOS ERROR]   File "../../build/scripts/hapbuilder.py", line 186, in <lambda>
[OHOS ERROR]     lambda: create_hap(options, options.hap_path),
[OHOS ERROR]   File "../../build/scripts/hapbuilder.py", line 124, in create_hap
[OHOS ERROR]     build_utils.check_output(packing_cmd)
[OHOS ERROR]   File "/home/pengweijie/openharmony/build/scripts/util/build_utils.py", line 226, in check_output
[OHOS ERROR]     child = subprocess.Popen(args,
[OHOS ERROR]   File "/home/pengweijie/openharmony/prebuilts/python/linux-x86/3.8.5/lib/python3.8/subprocess.py", line 854, in __init__
[OHOS ERROR]     self._execute_child(args, executable, preexec_fn, close_fds,
[OHOS ERROR]   File "/home/pengweijie/openharmony/prebuilts/python/linux-x86/3.8.5/lib/python3.8/subprocess.py", line 1702, 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'

回复
2022-6-13 20:21:37
陈浩南xxx
陈浩南xxx 回复了 陈浩南xxx
[OHOS INFO] [297/2187] ACTION //ark/ts2abc/ts2panda:npm_run_build(//build/toolchain/linux:clang_x64) [OHOS ERROR] [295/2187] ACTION //foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/medialibrary_data_ability:medialibrary_dynamic_hap(//build/toolchain/ohos:ohos_clang_arm) [OHOS ERROR] FAILED: obj/foundation/multimedia/medialibrary_standard/frameworks/innerkitsim...

我和你是同一个3.1 Release的版本, 也遇到了你上面说的三个错误; 还多了上面一条,怎么处理

 

回复
2022-6-13 20:22:46
liangkz_梁开祝
liangkz_梁开祝 回复了 陈浩南xxx
我和你是同一个3.1 Release的版本, 也遇到了你上面说的三个错误; 还多了上面一条,怎么处理

你的开发环境装有java没有?

$java --version

有没有Java的版本信息打印出来?

 

没有的话,安装一下:

$sudo apt install -y default-jre default-jdk ca-certificates-java

回复
2022-6-13 20:34:48
陈浩南xxx
陈浩南xxx 回复了 liangkz_梁开祝
你的开发环境装有java没有? $java --version 有没有Java的版本信息打印出来? 没有的话,安装一下: $sudo apt install -y default-jre default-jdk ca-certificates-java

按照你的方法解决了这个问题;    

回复
2022-6-14 10:15:48
陈浩南xxx
陈浩南xxx

后又出现 [OHOS ERROR]  packages/phone/make-boot.sh: 行 22: genext2fs:未找到命令    

解决办法:sudo apt install genext2fs

回复
2022-6-14 10:17:06
陈浩南xxx
陈浩南xxx

编译好了之后,还需要打包成img吗?  如果需要,我要怎么操作呢

 

回复
2022-6-14 10:37:38
liangkz_梁开祝
liangkz_梁开祝 回复了 陈浩南xxx
编译好了之后,还需要打包成img吗? 如果需要,我要怎么操作呢

编译成功了,会在out/packages/phone/images/目录下生成烧录镜像

回复
2022-6-15 19:16:18
wx630710ae8f754
wx630710ae8f754

楼主,我的报错跟你一模一样,到现在还在靠手动改代码解决,别人都没事,真是奇了怪了,我是完全按照官方文档一步步装的,我的ubuntu版本是20.04。楼主现在有找到更好的解决办法吗?然后我现在在3.2的环境下从没报过这个错,离了大谱。

回复
2023-4-20 15:41:02
arnoldawng
arnoldawng

编译一次需要多长时间啊

回复
2024-6-12 10:10:25
回复
    相关推荐