android系统构建系统

Jan. 21. 2016

2016年1月21日

Roughly speadking, build in software development is the process of “translating” source code files into executable binary code files[1]; and a build system is a collection of software tools that is used to facilitate the build process[2]. Despite the fact that different build systems have been “invented” and used for over three decades, the core algorithms used in most of them are not changed much since the first introduction of the directed acyclic graph ( DAG) by Make[3]. Popular build systems nowadays include the classical GNU Make, CMake, QMake, Ninja, Ant, Scons, and many others. In this note, I am going to demonstrate how to use some of these popular build systems to build C++ projects (to emphasize how the build systems work, the projects are extremely simplified).

大致而言, 内置软件开发是将源代码文件“转换”为可执行二进制代码文件的过程[1]; 构建系统是用于简化构建过程的软件工具的集合[2]。 尽管事实上已经“发明”了不同的构建系统并使用了三十多年,但自Make首次引入有向无环图(DAG)以来,大多数构建系统所使用的核心算法并未发生太大变化[3]。 如今,流行的构建系统包括经典的GNU MakeCMakeQMakeNinjaAntScons等。 在本说明中,我将演示如何使用其中一些流行的构建系统来构建C ++项目(为了强调构建系统的工作方式,这些项目被极大简化了)。

玩具项目 (Toy Project)

The toy project I am going to use will just produce an executable binary code file which simply print out the string “Hello World!” on the screen. Below is the architecture of the project (a name without extension represent a directory).

我将要使用的玩具项目将只产生一个可执行的二进制代码文件,该文件仅打印出字符串“ Hello World!”。 屏幕上。 下面是项目的体系结构(不带扩展名的名称代表目录)。

// Project Directory Tree/home/[username]/project-hello  bin   include       print.cpp     print.h   lib   obj   src       main.cpp

Below are the code in the three source code files.

下面是三个源代码文件中的代码。

// print.h#include <iostream>#include <string>class Print{public:    void operator()(const std::string&);};// print.cpp#include “print.h”void Print::operator()(const std::string &str){    std::cout << str;}// main.cpp#include “../include/print.h”int main(int argc, char* argv[]){    Print print;    print(“Hello World!\n”);    return 0;}

GNU Make (GNU Make)

GNU Make build projects following the information provided in a file called makefile[4]. To build a project, one needs to write a makefile to tell GNU Make how. In the example below, I demonstrate how to write makefile and build an extremely simplified project. Put the following Makefile into the root directory of the project, i.e. the project-hello directory.

GNU Make构建项目遵循名为makefile [4]的文件中提供的信息。 要构建一个项目,需要编写一个makefile来告诉GNU Make如何。 在下面的示例中,我演示了如何编写makefile并构建一个极其简化的项目。 将以下Makefile放入项目的根目录,即project-hello目录。

# MakefileCXX = g++AR = arSOURCEPATH = $(PWD)/srcINCLUDEPATH = $(PWD)/includeOBJECTPATH = $(PWD)/objLIBRARYPATH = $(PWD)/libBINARYPATH = $(PWD)/binall: hello-static hello-sharedhello-static: print-static $(SOURCEPATH)/main.cpp    $(CXX) $(SOURCEPATH)/main.cpp -L$(LIBRARYPATH) -lprint_static -o $(BINARYPATH)/$@hello-shared: print-shared $(SOURCEPATH)/main.cpp    $(CXX) $(SOURCEPATH)/main.cpp -L$(LIBRARYPATH) -lprint_shared -o$(BINARYPATH)/$@    export LD_LIBRARY_PATH=”$(LIBRARYPATH)”print-static: obj-static    $(AR) -cru $(LIBRARYPATH)/libprint_static.a $(OBJECTPATH)/print_static.oprint-shared: obj-shared    $(CXX) -shared $(OBJECTPATH)/print_shared.o -o $(LIBRARYPATH)/libprint_shared.soobj-static: $(INCLUDEPATH)/print.h    $(CXX) -c -Wall $(INCLUDEPATH)/print.cpp -o $(OBJECTPATH)/print_static.oobj-shared: $(INCLUDEPATH)/print.h    $(CXX) -fPIC -c $(INCLUDEPATH)/print.cpp -o $(OBJECTPATH)/print_shared.oclean:    find . -name “*.so” -type f -print0 | xargs -0 rm -f    find . -name “*.a”  -type f -print0 | xargs -0 rm -f    find . -name “*.o”  -type f -print0 | xargs -0 rm -f    rm -f $(BINARYPATH)/*

With the Makefile provided about, an executable program, static library, and shared library can be produced by respectively running make all (or simply make), make print-static, and make print-shared commands in terminal. To remove all generated binary code files, one just needs to run the command make clean. For more details, please check [4] or other similar references.

使用提供的Makefile ,可以通过分别在终端中运行make all (或简单地make ), make print-staticmake print-shared命令来生成可执行程序,静态库和共享库。 要删除所有生成的二进制代码文件,只需运行命令make clean 。 有关更多详细信息,请检查[4]或其他类似参考。

QMake (QMake)

Like CMake, QMake is an open-source, cross-platform build system. QMake was created by Trolltech (now owned by Digia), and shipped with the Qt toolkit [5]. Essentially QMake automates the generation of Makefiles. Although Qt has its own moc (meta-object compiler) and uic (user-interface compiler) for its own project building process, qmake can be used for building any C++ projects with or without using these features. Next, I demonstrate how to use qmake to build our toy project.

像CMake一样,QMake是一个开源,跨平台的构建系统。 QMake由Trolltech (现归Digia拥有)创建,并随Qt工具包一起提供[5]。 本质上,QMake使Makefile的生成自动化。 尽管Qt在其自身的项目构建过程中具有自己的moc (元对象编译器)和uic (用户界面编译器),但是无论是否使用这些功能,qmake均可用于构建任何C ++项目。 接下来,我演示如何使用qmake来构建我们的玩具项目

To tell qmake how to generate Makefiles appropriately, project (.pro, .pri) files are needed. Although in some trivial special cases, the .pro file automatically generated by running qmake in -project mode may be enough, in most cases, project files need to be manually edited to meet the production build requirements. Below I give another directory tree to include the project files I added for building the toy project (again names without extension are directories).

为了告诉qmake如何适当地生成Makefile,需要项目( .pro.pri )文件。 尽管在一些琐碎的特殊情况下,通过在-project模式下运行qmake自动生成的.pro文件可能就足够了,但在大多数情况下,需要手动编辑项目文件以满足生产构建的要求。 在下面,我给出了另一个目录树,其中包括为构建玩具项目而添加的项目文件(同样,不带扩展名的目录)。

// Project Directory Tree project-hello     project-hello.pro     bin       include           print.cpp         print.h       lib           lib.pro       src           main.cpp          src.pro

Below are the three project files.

以下是三个项目文件。

# project-hello.proTEMPLATE = subdirsSUBDIRS += libSUBDIRS += srcCONFIG += ordered# src.proTEMPLATE = appTARGET = helloDESTDIR = ../binDEPENDPATH += .LIBS += -L../lib -lprint-static # link against static library#LIBS += -L../lib -lprint-shared # link against shared librarySOURCES += main.cpp# lib.pro, for building static libraryTEMPLATE = libTARGET = print-staticVERSION = 1.0.0CONFIG += staticlib# DirectoriesDESTDIR = ../libINCLUDEPATH += ../includeDEPENDPATH += ../includeHEADERS += ../include/print.hSOURCES += ../include/print.cpp# lib.pro, for building shared libraryTEMPLATE = libTARGET = print-sharedVERSION = 1.0.0CONFIG += dll# DirectoriesDESTDIR = ../libINCLUDEPATH += ../includeDEPENDPATH += ../includeHEADERS += ../include/print.hSOURCES += ../include/print.cpp

After the project files are created and edited appropriately, we are ready to build our toy project. By running qmake -makefile command (as -makefile is the default mode, we may simply run qmake command) to generate Makefiles, and make command, the project will be build successfully.

在适当地创建并编辑了项目文件之后,我们就可以构建玩具项目了。 通过运行qmake -makefile命令(如-makefile是默认的模式下,我们可以简单地运行qmake命令)生成Makefile s,而make的命令,该项目将是构建成功。

Possibly you have noticed that in the above project files, I gave two versions of the project file, lib.pro. One is for building a static library, the other is for shared library. If the executable binary code file is linked against the static library, it can run without loading anything else. But if it is linked against the shared library, the executable binary code file needs to load the shared library to get the code implementing the functor (aka function object), print. We have three different ways to tell the system how to find the shared library. One is to copy the shared library file to the ./bin directory; the second is to copy the shared library file to the system directory /usr/local/lib; the third is to put the line

可能您已经注意到,在上述项目文件中,我给出了两个版本的项目文件lib.pro 。 一种用于构建静态库 ,另一种用于共享库 。 如果可执行二进制代码文件与静态库链接,则可以运行而无需加载其他任何文件。 但是,如果将其链接到共享库,则可执行二进制代码文件需要加载共享库,以获取实现functor (aka 函数对象 ) print 。 我们有三种不同的方式来告诉系统如何找到共享库。 一种是将共享库文件复制到./bin目录。 第二种是将共享库文件复制到系统目录/usr/local/lib ; 第三是把线

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/[username]/project-hello/lib

into the hidden file /home/[username]/.bash_profile.

到隐藏文件/ /home/[username]/.bash_profile

GYP —元构建系统 (GYP — A Meta-Build System)

GYP, abbreviation for Generate Your Projects, is a Meta-Build system, a build system that generates other build systems[8]. Basically, it is a python dictionary[8], which contains all information on how to generate your project. In the entire gyp file as a python dictionary, you can have four different types of data structures, string, integer, list, and again, dictionary. Not only can you set up your project, but also execute commands. Next, I demonstrate how to use it to generate our toy project, and build it. For a detailed tutorial on gyp, the official documentation [8] is thorough and decent.

GYPGenerate Your Projects的缩写,是一个元构建系统 ,是一个生成其他构建系统的构建系统[8]。 基本上,它是python字典 [8],其中包含有关如何生成项目的所有信息。 在整个gyp文件(作为python字典)中,您可以具有四种不同类型的数据结构, stringintegerlist以及dictionary 。 您不仅可以设置项目,还可以执行命令。 接下来,我演示如何使用它来生成我们的玩具项目并进行构建。 有关gyp的详细教程,官方文档[8]详尽而体面。

# project-hello.gyp{    ‘targets’: [{        ‘target_name’: ‘hello-static’,        ‘type’: ‘static_library’,        ‘include_dirs’: [‘include’,],        ‘sources’: [            ‘include/print.cpp’,            ‘include/print.h’,        ],    }, {        ‘target_name’: ‘hello-shared’,        ‘type’: ‘shared_library’,        ‘include_dirs’: [‘include’,],        ‘sources’: [            ‘include/print.cpp’,            ‘include/print.h’,        ],        ‘cflags’: [‘-fPIC’,],    }, {        ‘target_name’: ‘hello-gyp’,        ‘type’: ‘executable’,        ‘include_dirs’: [            ‘<(DEPTH)’,            ‘<(DEPTH)/include’,        ],        ‘dependencies’: [            ‘hello-static’,            #’hello-shared’,        ],        ‘sources’: [            ‘src/main.cpp’,            ‘include/print.h’,        ],    },],}

Using gyp, projects for most build systems can be generated. To choose a specific build system for out projects, one just needs to specify it when invoking the generator command gyp by setting -f build_system_name. Below, I demonstrate this for generating projects for both GNU Make and Ninja build systems. For instructions for generating projects for other build systems, please refer to the official documentation[8].

使用gyp ,可以生成大多数构建系统的项目。 要选择一个特定的构建系统淘汰项目,一个只需要指定它调用生成命令时gyp通过设置-f build_system_name 。 下面,我将演示如何为GNU MakeNinja构建系统生成项目。 有关为其他构建系统生成项目的说明,请参考官方文档[8]。

gyp project-hello.gyp -f make — depth=. — generator-output=build/makefilescd build/makefilesmakegyp project-hello.gyp -f ninja — depth=. — generator-output=build/ninjacd build/ninjaninja -C out/Default/

Although projects for most build systems can be generated with gyp generator, Qt project can not be generated with gyp. This causes some inconvenience sometimes when people needs to use something like the widgets from Qt framework, but for some reason, switching the build system from gyp to qmake is not possible, at least practically. In this case, one may try to “embed” some qmake build system features, say moc, the meta-object compiler into gyp system. In my BuildSystems repository, I included one example project, which uses both widgets and signal-slot from qt framework. I used gyp with moc “embedded” to build the project. If you are interested, you can check the code and scripts here.

尽管大多数构建系统的项目都可以使用gyp generator生成,但是Qt项目不能使用gyp生成。 有时,当人们需要使用Qt框架中的小部件之类的东西时,这会带来一些不便,但是由于某种原因,至少在实际上,不可能将构建系统从gyp切换到qmake。 在这种情况下,可以尝试“嵌入”一些qmake的构建系统的特点, 交通部说, 元对象编译成GYP系统。 在BuildSystems存储库中,我包括一个示例项目,该项目同时使用了qt框架中的小部件信号插槽 。 我将gyp与“嵌入”的moc一起构建了该项目。 如果您有兴趣,可以在此处检查代码和脚本。

翻译自: https://medium.com/swlh/a-brief-introduction-to-build-systems-1e45cb1cf667

android系统构建系统

http://www.taodudu.cc/news/show-6077084.html

相关文章:

  • linux用c进程并行,Linux下的C / C ++使用多线程
  • 声波牙刷的全球与中国市场2022-2028年:技术、参与者、趋势、市场规模及占有率研究报告
  • Linux Make(Makefile)由浅入深的学习与示例剖析
  • Dom 复习
  • 被“傲慢”击溃的国外大牌们,终于轮到他们抄袭了?
  • 数据库 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\test1.mdf' 已存在。请选择其他数据库
  • 小米有品众筹仅249!Oclean X智能触屏电动牙刷6日劲爆开抢
  • 欧可林Oclean X Pro旗舰版:大学生的私人口腔医生
  • MAYA简单操作讲解1--入门干货
  • Maya 界面
  • Maya10个非常实用的操作技巧,让你轻松玩转Maya
  • 新手学习MAYA的几个建议
  • maya python 的简单使用
  • 3.3KW车载充电机开关电源设计方案资料数字控制单相PFC与全桥LLC 3.3KW 车载充电机OBC
  • 3.3KW车载充电机开关电源方案数字控制单相PFC与全桥LLC
  • 电源开关电源200W 12V 24V,电源架构PFC+LLC+同步整流,高效率高功率因数
  • 什么是主动式计算机用户,电脑电源主动PFC是什么意思
  • PFC电源设计与电感设计计算学习笔记
  • TI PFC+LLC解决方案在工业电源中的应用-电子研习社
  • 一文讲解电源技术中的安森美深力科NCP1680AAD1R2G CrM PFC控制器IC 详情讲解
  • PFC的原理与实现
  • 开关电源-反激+单级PFC超低纹波超低THD
  • L1-084 拯救外星人 C语言
  • Python项目:外星人入侵(汇总)
  • 解决方案:macOS Mojave下Pycharm运行pygame无法加载外星人游戏图片以及无法修改颜色
  • ftp搭建教程
  • 关于搭建FTP服务器
  • linux Centos的ftp搭建-配置-上传下载文件--全面版
  • ftp搭建历程
  • FTP搭建

android系统构建系统_构建系统简介相关推荐

  1. 微信点餐系统java教程_构建微服务微信点餐系统教程

    凡是认购学员提供全部的问题解答,有问题请大家私信提出问题. 微服务是目前行业的热门技术架构,随着移动互联网愈演愈烈,微信支付和外卖成为人们的**,为了让广大技术爱好者学习微服务架构和业务结合,从而研发 ...

  2. MATLAB虚拟动画显示球杆,球杆系统实验教程_球杆系统根轨迹代码matlab,球杆系统的状态反馈实验总结-软件测试工具类资源...

    基于球杆的控制系统分析与设计实验教程分析和系统的测定 前言 臼动控制珄论是自动控制及相关专业的必修专业基础课,自动控制理论实验是学习和掌 握控制系统分析和设计方法最有效的途径之 机电控制系统分析设计是 ...

  3. 苹果系统和安卓系统的区别_安卓系统用久了会卡,苹果系统就能一直流畅?

    这么多年以来,无数人问过我这个问题,刚开始我试图用一些偏专业的方式解释,但是结果证明,效果并不好. 诚然,对于那部分朋友来讲,应用审查机制.消息推送机制和伪后台,这些专业名词理解起来,难度确实非常大. ...

  4. 华为鸿蒙系统源码_鸿蒙系统 IO 栈分析 | 解读鸿蒙源码

    华为的鸿蒙系统开源之后第一个想看的模块就是 FS 模块,想了解一下它的 IO 路径与 linux 的区别.现在鸿蒙开源的仓库中有两个内核系统,一个是 liteos_a 系统,一个是 liteos_m ...

  5. 前端构建工具_构建工具

    前端构建工具 深度JavaScript (Deep JavaScript) Choosing a development tool based on its popularity isn't a ba ...

  6. 一直在构建版本_构建系统与代码结构SpringBoot

    从今天开始,我们进入SpringBoot的使用环节,这一部分包含了构建系统,自动配置,如何运行应用程序,自然也包括了一些使用SpringBoot的最佳实践.关于SpringBoot的介绍,Anders ...

  7. 系统结构图 数据结构_数据结构图简介

    系统结构图 数据结构 What you are going to learn? 你要学什么? In this article, we learn about the introduction to G ...

  8. android简单小项目实例_自学(系统学)Python了那么久, 想就业? 几个简单小项目让你通过面试!...

    本人从事Python开发多年,精通爬虫,web,熟悉其他方向,好多小伙伴私聊我说,我看了你的文章后,我学习了,但是对于项目这块还是不是很熟悉,如何快速掌握几个小项目,以及几个可以面试的项目.欢迎大家订 ...

  9. 系统稳定性 衡量_衡量系统安全性

    系统稳定性 衡量 As a follow up on changing the default password, I was running an overall security audit on ...

  10. thinkpad重装系统不引导_重装系统时,如何判断Windows的启动方式是Legacy还是UEFI?...

    众所周知,BIOS启动模式有UEFI+GPT和Legacy+MBR两种,如今大多数新机型电脑都采用了UEFI的启动模式来引导系统,即便如此,仍有部分电脑采用Legacy启动模式.这两种启动模式究竟有什 ...

最新文章

  1. 为什么高手都懂得拆解目标?
  2. 在控制台输出口,根据内存地址,找到被过度释放的对象!
  3. java点击关闭弹出窗口_java – JPopupMenu在子弹出窗口打开时关闭
  4. csv phoenix 导入_phoenix学习
  5. go15---select
  6. mysql触发器中访问mssql数据表_[数据库]一个利用触发器(trigger)实现数据库表的审计功能(audit)的例子--针对ms sql实现...
  7. linux java keytool_JDK自带的keytool证书工具详解
  8. 服务器虚拟成一个共用一台ipsan,IPSAN(四)IPSAN多路径设置(服务端)
  9. 全国各省会城市经纬度(包含港澳台)
  10. 桌面计算机图标无法显示属性,Win7系统桌面图标显示异常的解决方法大全
  11. ubuntu20.04不能切换输入法
  12. Matla + SVD 求解变换矩阵
  13. 2020年Top 100开发者工具列表汇总
  14. 【趣味】智能AI祝福语
  15. 刷题记录:牛客NC20811蓝魔法师
  16. 论文笔记之Deep Learning on Image Denoising: An Overview
  17. 分布式文件系统FastDFS集群搭建
  18. 【Java】JavaMail编程实现邮件客户端-OutBox InBox
  19. keil5安装国民技术芯片包
  20. 圣科鲁兹 计算机专业,加州大学圣克鲁兹分校计算机科学硕士

热门文章

  1. addon游戏_MOD Herobrine Addon
  2. python 处理 Excel 表格
  3. 什么 ? 陪玩都月入过忘拉~这不得python采集一下
  4. wordpress 数据库_如何在WordPress中创建视频库(逐步)
  5. 【程序人生】机灵鹤六月份的月度总结
  6. 计算机的键盘组合件,电脑组合键盘快捷键大全
  7. css表格省略号,CSS 文本和表格中文字溢出显示省略号
  8. 后台管理系统中的antd vue中的问题(动态加载列表a-select-option,后台管理中a-selct-option的回显)
  9. Exsel 设置固定表头
  10. excel2021 打印圆不圆