Ubuntu18.04下安装Gn软件(和Ninja配合使用的,代替CMake、Automake + Makefile)

  • Gn软件是用来生成Ninja规则的,类似于Linux中的Automake、Cmake、Qmake工具;

    • Gn软件的源码地址:https://gitee.com/openharmony/third_party_gn
    • Gn在大型工程中好用,在小型工程中太繁琐
  • 如果你使用的是Windows + MSYS2 + MinGW64,不能安装Gn,只能使用Linux发行版,如Ubuntu。

  • Ubuntu中安装Gn

    • 不能通过apt-get install的方式安装,如果你能架梯子,可以去这个网站下载:https://gn.googlesource.com/gn/ 安装包
    • 已安装Git、GCC、Ninja、Python 3、Clang-8或以上版本
  • sudo apt-get install clang-8 安装Clang-8或以上版本编译器

  • cd /usr/bin/ 进入默认软件目录

  • sudo ln -s …/lib/llvm-8/bin/clang clang 创建链接

  • sudo ln -s …/lib/llvm-8/bin/clang++ clang++ 创建链接

  • clang --version 测试编译器

jim@ubuntu:/usr/bin$ clang --version
clang version 8.0.0-3~ubuntu18.04.2 (tags/RELEASE_800/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

  • 在命令行中进入你想要的目录,如~/openHarmony
  • git clone git@gitee.com:openharmony/third_party_gn.git 下载Gn软件源码
    • 注意:如果用开源鸿蒙的Gn源码仓库,亲测./out/gn_unittests自测时会报错,但不影响使用,使用官方库就不会报错
  • cd third_party_gn/ 进入源码目录
  • python build/gen.py 生成Ninja编译文件,类似于Makefile文件
  • ninja -C out 编译,时间有点久,要几分钟
jim@ubuntu:~/0_Git/third_party_gn$ ninja -C out
ninja: Entering directory `out'
[297/297] LINK gn_unittests
  • ./out/gn_unittests 测试Gn软件,如果你是使用Gn官网的源码会测试正常,如果用开源鸿蒙的源码,则会出现下面报错,忽略下面报错,直接下一步
jim@ubuntu:~/0_Git/third_party_gn$ ./out/gn_unittests
[390/687] NinjaRustBinaryTargetWriterTest.TransitiveRustDeps[139769390700416:0311/003324.720801:FATAL:values.cc(239)] Check failed: is_list(). 

Aborted (core dumped)
  • sudo cp ./out/gn /usr/bin 将编译完的程序拷贝到默认程序路径,不这么做的话就需要你自己加环境变量了,make install命令也是类似的作用

  • 使用gn help查看是否安装成功

jim@ubuntu:~/0_Git/third_party_gn$ gn help

Commands (type "gn help <command>" for more help):
  analyze: Analyze which targets are affected by a list of files.
  args: Display or configure arguments declared by the build.
  check: Check header dependencies.
  clean: Cleans the output directory.
  clean_stale: Cleans the stale output files from the output directory.
  desc: Show lots of insightful information about a target or config.
  format: Format .gn files.
  gen: Generate ninja files.
  help: Does what you think.
  ls: List matching targets.
  meta: List target metadata collection results.
  outputs: Which files a source/target make.
  path: Find paths between two targets.
  refs: Find stuff referencing a target or file.

为了能让大家更好的学习鸿蒙(HarmonyOS NEXT)开发技术,这边特意整理了《鸿蒙开发学习手册》(共计890页),希望对大家有所帮助:https://qr21.cn/FV7h05

《鸿蒙开发学习手册》:

如何快速入门:https://qr21.cn/FV7h05

  1. 基本概念
  2. 构建第一个ArkTS应用
  3. ……

开发基础知识:https://qr21.cn/FV7h05

  1. 应用基础知识
  2. 配置文件
  3. 应用数据管理
  4. 应用安全管理
  5. 应用隐私保护
  6. 三方应用调用管控机制
  7. 资源分类与访问
  8. 学习ArkTS语言
  9. ……

基于ArkTS 开发:https://qr21.cn/FV7h05

  1. Ability开发
  2. UI开发
  3. 公共事件与通知
  4. 窗口管理
  5. 媒体
  6. 安全
  7. 网络与链接
  8. 电话服务
  9. 数据管理
  10. 后台任务(Background Task)管理
  11. 设备管理
  12. 设备使用信息统计
  13. DFX
  14. 国际化开发
  15. 折叠屏系列
  16. ……

鸿蒙开发面试真题(含参考答案):https://qr18.cn/F781PH

鸿蒙开发面试大盘集篇(共计319页):https://qr18.cn/F781PH

1.项目开发必备面试题
2.性能优化方向
3.架构方向
4.鸿蒙开发系统底层方向
5.鸿蒙音视频开发方向
6.鸿蒙车载开发方向
7.鸿蒙南向开发方向

  • 12
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值