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

发布于 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
回复
举报
回复
添加资源
添加资源将有机会获得更多曝光,你也可以直接关联已上传资源 去关联
    相关推荐