CMake和Make之间的区别

CMake与Make的区别及使用说明 CMake是一个跨平台的构建工具,它使用CMakeLists.txt文件来描述项目的构建规则。Make是一个早期的构建工具,它使用Makefile来描述项目的构建规则。通过执行make命令,Make工具会读取Makefile并根据规则执行相应的操作,以便生成目标文件或可执行文件。在这个示例中,CMakeLists.txt定义了一个名为app的项目,它包含了main.c和utils.c这两个源文件。命令,Make工具会读取生成的Makefile并执行构建操作,生成可执行文件app。 阅读详情
本文翻译的是一篇英文文档,主要讲述的是CMake和Make之间的区别。下文中首先列出文章的中文翻译,然后紧接着的是英文原文。

下面是中文翻译部分:
    编程人员已经使用CMake和Make很长一段时间了。当你加入一家大公司或者开始在一个具有大量代码的工程上开展工作时,你需要注意所有的构建。你需要看到处跳转的”CMakeLists.txt”文件。你应该会在终端使用”cmake”和”make”。很多人都是盲目的跟着操作说明而并不在意我们已何种方式去做我们需要做的事。构建的整个过程是什么?为什么要用这种方式去组织?Cmake和Make之间有什么区别?这有关系吗?他们可以互相转换吗?
    事实证明,它们之间有很多的不同。理解它们之间的不同很重要,这样你可以确保在使用的过程中不会陷入麻烦。在讲述它们之间的区别之前,我们首先来看看它们是什么。
Make
    要设计一个软件系统,我们首先编写源码,然后通过编译器编译和创建可执行文件。可执行文件就是要实现最终功能的文件。“Make”是一个工具,它控制可执行程序和程序源文件中非源码文件的生成。
    “Make”工具需要清楚的知道如何构建程序。 它通过一个叫做“makefile”的文件知晓如何构建你的程序。这个文件列出了所有的非源码文件以及如何由别的文件来计算它。当你编写了一个程序,你应该为它写一个makefile文件,这样才有可能通过使用“Make”来构建和安装你的程序。 很简单的事情。如果你不理解的话,多读几遍这一段文字,因为理解这一段文字对于接下来的篇幅很重要。
为什么需要“Make”
    需要”make”的一个原因是,它可以使得终端用户构建和安装你的应用包,而不用去详细的了解它具体是如何做到的。每一个工程都有它自己的规则和细微的差别,这会使得每次在复用的时候会变得很痛苦。这就是我们创建这个makefile文件的原因。 构建步骤精确的记录在你提供的这个makefile文件中。“Make” 当源码文件发生变化时自动的指出哪一个文件需要更新。 同时它也自动确定以适当的顺序进行更新文件,当一个非源码文件依赖的另一个非源码文件发生改变时。
    每次当我们改变了系统中的一小部分源码的时候,重新编译整个程序的效率是很低的。因此,党我们改变了一小部分的源码文件的时候重新执行“Make”,它将不会重新编译整个程序。它仅仅更新那些直接或者间接依赖这些改变了的源码文件的非源码文件。很酷吧!“Make” 不局限于具体的语言。对于程序中的每一个非源码文件,makefile文件详细的说明了执行需要的shell命令。这些shell命令能够启动编译器产生目标文件,链接器产生可执行文件,ar更新库,镜像生成器格式化文档,等等。。。Make不仅仅局限于构建一个包。你也可以安装或者卸载一个包,生成索引表或者其他一些你经常做的值得你写下来怎么去做的事情。
CMake
    CMake支持跨平台Make。 CMake 辨别使用那种编译器去编译给出的源码种类。如果你不知道使用何种编译器,你不能使用相同的编译器去编译所有不同种类的源码。你可以手动的指用何种编译器,但是这将变得繁琐和痛苦。CMake为每一种类型的目标平台按照正确的顺序调用命令。因此,将有很多非显式的命令,比如$(CC).
    如果你是代码强迫症,请继续往下读。如果你不喜欢这一切,你可以跳过这一部分。一般的编译/链接标识处理头文件、库文件、以及重定位其他平台无关和构建系统独立命令。调试标识被包含,通过设置变量CMAKE_BUILD_TYPE 为“debug”,或者在调用程序的使用传递给CMake:cmake -DCMAKE——BUILD——TYPE:STRING=Debug。
    CMake也提供平台无关的包含,通过‘-fPIC’标志(POSITION_INDEPENDENT_CODE属性)。因此,更多隐式的设置能够在CMake命令中实现,在makefile文件中也可以(通过使用COMPILE_FLAGS或者相关的属性)。当然,CMake在集成第三方库(像OpenGL)方面也变得更加轻便。
它们之间有什么不同点?
    如果你要使用编译脚本,构建的过程中有一个步骤,也就是需要在命令行中输入”make”。 对于CMake,需要进行2步:第一,你需要配置你的编译环境(可以通过在你的编译目录中输入cmake ,也可以通过使用GUI客户端)。这将创建一个等效的,依赖你选择的编译环境的编译脚本或其他。编译系统可以传递给CMake一个参数。总之,CMake根据你的系统配置选择合理的的默认的选择。第二,你在你选择的编译系统中执行实际的构建。
    你将进入GNU构建系统领域。 如果你不熟悉这个,这一段对于你来说就是碎碎念了。现在,说完了一些严肃的警告,往下走把! 我们可以使用Autotool来比较CMake。当我们这样做的时候,我们会发现Make的缺点,而且这就是Autotool产生的理由了。我们可以看到CMake明显比Make优越的理由了。Autoconf 解决了一个重要的问题,也就是说与系统有关的构建和运行时信息的的可信赖发现。但是,这仅仅是轻便软件的开发中的一小部分。作为结尾,GNU工程已经开发了一系列集成的实用程序,用于完成Autoconf开始之后的工作:GNU构建系统中最重要的组件是Autoconf, Automake, and Libtool.
    “Make”就不能那样做了,至少不修改任何东西是做不到的。你可以自己做所有的跨平台工作,但是这将花费很多时间。CMake解决了这个问题,但是与此同时,它比GNU构建系统更有优势:

  • 用于编写CMakeLists.txt文件的语言具有可读性和很容易理解。
  • 不仅可以使用“Make” 来构建工程。
  • 支持多种生产工具,比如Xcode, Eclipse, Visual Studio, etc.
        CMake与Make对比具有以下优点:
  • 自动发现跨平台系统库。
  • 自动发现和管理的工具集
  • 更容易将文件编译进共享库, 以一种平台无关的方式或者以比make更容易使用的的生成方式。
        CMake不仅仅只“make”,所以它变得更复杂。从长远来看,最好能够学会使用它。如果你仅仅在一个平台上构建小的工程,“Make”更适合完成这部分工作。

下面是本文的英文原文部分:
CMake vs Make
    Programmers have been using CMake and Make for a long time now. When you join a big company or start working on a project with a large codebase, there are all these builds that you need to take care of.You must have seen those “CMakeLists.txt” files floating around. You are supposed to run “cmake” and “make” commands on the terminal. A lot of people just follow the instructions blindly, not really caring about why we need to do things in a certain way. What is this whole build process and why is it structured this way? What are the differences between CMake and Make? Does it matter? Are they interchangeable?
    As it turns out, they are quite different. It is important to understand the differences between them to make sure you don’t get yourself in trouble. Before getting into the differences, let’s first see what they are.
Make
    The way in which we design a software system is that we first write code, then the compiler compiles it and creates executable files. These executable files are the ones that carry out the actual task. “Make” is a tool that controls the generation of executables and other non-source files of a program from the program’s source files.
    The “Make” tool needs to know how to build your program.It gets its knowledge of how to build your program from a file called the “makefile”. This makefile lists each of the non-source files and how to compute it from other files. When you write a program, you should write a makefile for it, so that it is possible to use “Make” to build and install the program.Simple stuff! If you didn’t understand it, go back and read the paragraph again because it’s important for the next part.
Why do we need “Make”?
    The reason we need “Make” is because it enables the end user to build and install your package without knowing the details of how it’s done. Every project comes with its own rules and nuances, and it can get quite painful every time you have a new collaborator. That’s the reason we have this makefile.The details of the build process are actually recorded in the makefile that you supply. “Make” figures out automatically which files it needs to update, based on which source files have changed.It also automatically determines the proper order for updating the files, in case one non-source file depends on another non-source file.
    Recompiling the entire program every time we change a small part of the system would be inefficient.Hence, if you change a few source files and then run “Make”, it doesn’t recompile the whole thing. It updates only those non-source files that depend directly or indirectly on the source files that you changed.Pretty neat!“Make” is not limited to any particular language. For each non-source file in the program, the makefile specifies the shell commands to compute it. These shell commands can run a compiler to produce an object file, the linker to produce an executable, ar to update a library, Makeinfo to format documentation, etc.“Make” is not limited to just building a package either. You can also use “Make” to control installing or uninstalling a package, generate tags tables for it, or anything else you want to do often enough to make it worth while writing down how to do it.
CMake
    CMake stands for Cross-platform Make. CMake recognizes which compilers to use for a given kind of source.In case you didn’t know, you can’t use the same compiler to build all the different kinds of sources. You can do this manually every time you want to build your project, but it would be tedious and painful. CMake invokes the right sequence of commands for each type of target. Therefore, there is no explicit specification of commands like $(CC).
    For coding junkies who really want the gory details, read on. If you are not into all that, you can skip to the next section. All the usual compiler/linker flags dealing with the inclusion of header files, libraries, etc are replaced by platform independent and build system independent commands.Debugging flags are included by either setting the variable CMAKE_BUILD_TYPE to “Debug”, or by passing it to CMake when invoking the program:cmake -DCMAKE_BUILD_TYPE:STRING=Debug.
    CMake also offers the platform independent inclusion of the ‘-fPIC’ flag (via the POSITION_INDEPENDENT_CODE property) and many others. Still, more obscure settings can be implemented by hand in CMake just as well as in a Makefile (by using COMPILE_FLAGS and similar properties). Of course CMake really starts to shine when third party libraries (like OpenGL) are included in a portable manner.
What is the difference?
    The build process has one step if you use a Makefile, namely typing “make” at the command line.For CMake, there are two steps: First, you need to setup your build environment (either by typing cmake in your build directory or by running some GUI client).This creates a makefile or something equivalent, depending on the build system of your choice (e.g. Make on *nix, VC++ or MinGW on Windows, etc). The build system can be passed to CMake as a parameter. However, CMake makes reasonable default choices depending on your system configuration. Second, you perform the actual build in the selected build system.
    We are going to jump into the GNU build system territory here.If you are not familiar with that, this paragraph might look like jibber-jabber to you. Alright, now that I have given the statutory warning, let’s move on!We can compare CMake with Autotools. When we do that, we can see the shortcomings of Make, and they form the reason for the creation of Autotools. We can also see the obvious advantages of CMake over Make. Autoconf solves an important problem i.e. reliable discovery of system-specific build and runtime information. But this is only a small part in the development of portable software. To this end, the GNU project has developed a suite of integrated utilities to finish the job Autoconf started: the GNU build system, whose most important components are Autoconf, Automake, and Libtool.
    “Make” can’t do that, at least not without modifying it anyway!You can make it do all that stuff but it would take a lot of time maintaining it across platforms. CMake solves the same problem, but at the same time, it has a few advantages over the GNU Build System:

  • The language used to write CMakeLists.txt files is readable and easier to understand.
  • It doesn’t only rely on “Make” to build the project.
  • It supports multiple generators like Xcode, Eclipse, Visual Studio, etc.

    When comparing CMake with Make, there are several advantages of using Cmake:

  • Cross platform discovery of system libraries.
  • Easier to compile your files into a shared library in a platform agnostic way, and in general easier to use than make.
  • Automatic discovery and configuration of the toolchain.

    CMake does more than just “make”, so it can be more complex. In the long run, it’s better to learn how to use it. If you have just a small project on only one platform, then maybe “Make” can do a better job.

Claude Desktop新功能:让非技术人士也能自主编程 摘要: Anthropic近日在Claude桌面应用中集成了Claude Code功能,显著降低了非技术用户的使用门槛。Claude Code作为代理式编程工具,支持多任务并行处理、Git隔离和可视化会话管理,无需命令行操作即可实现代码调试、重构等复杂任务。新增的“计划模式”通过先分析后执行的流程,确保安全性,使产品经理、数据分析师等非开发者也能参与技术工作。这一更新标志着AI技术正打破专业壁垒,让领域专家无需编码背景即可利用高级工具,推动技术民主化。 阅读详情

相关推荐

用Simulink复现Hopf振荡器:从数学公式到稳定极限环的保姆级仿真教程

本文详细介绍了如何在Simulink中实现Hopf振荡器,从数学原理到仿真建模的全过程。通过参数调试和波形分析,帮助读者掌握Hopf振荡器的核心特性及其在机器人控制等领域的应用。特别强调了自适应调节技巧,提升系统稳定性和鲁棒性。

weixin_29261711的博客 442

Make与CMake

1.Make与CMake 首先先来了解一下gcc,gcc是GNU Compiler Collection(就是GNU编译器套件),也可以简单认为是编译器,它可以编译很多种编程语言(包括C、C++、Objective-C、Fortran、Java等等)。当我们的程序只有一个源文件时,直接就可以用gcc命令编译它。 但是当程序包含很多源文件时,用gcc命令逐个去编译时,就很容易混乱而且工作量大。所以就出现了Make工具。它是一个自动化编译工具,我们可以使用一条命令实现完全编译,但是需要编写一个规则文件,Make

AAAA202012的博客 1万+

STM32 USB AUDIO实战指南——从零构建音频设备

本文详细介绍了如何使用STM32F407构建USB音频设备,从硬件准备到软件配置,再到音频播放和录制功能的实现。通过STM32CubeMX配置和实战代码示例,帮助开发者快速掌握USB Audio Class规范,实现低延迟、高质量的音频传输,适用于语音交互、音乐播放等多种场景。

weixin_42549037的博客 483

CMake与Make

大家都知道,写程序大体步骤为: 1.用编辑器编写源代码,如.c文件。 2.用编译器编译代码生成目标文件,如.o。 3.用链接器连接目标代码生成可执行文件,如.exe。 但如果源文件太多,一个一个编译时就会特别麻烦,于是人们想到,为什么不设计一种类似批处理的程序,来批处理编译源文件呢,于是就有了make工具,它是一个自动化编译工具,你可以使用一条命令实现完全编译。但是你需要编写一个规

shaoxiaohu的专栏 1万+

Keysight ADS新手必看:3分钟搞定TDR模拟的保姆级教程(附差分信号设置技巧)

本文为Keysight ADS新手提供TDR模拟的保姆级教程,详细介绍了从基础环境准备到差分信号设置的全流程。通过内置模板调用、待测器件连接和仿真结果解读,帮助用户快速掌握TDR模拟技术,特别包含差分信号配置技巧,提升信号完整性分析效率。

weixin_30872157的博客 195

从solidworks导出URDF模型

一、下载sw_urdf_exporter插件 ROS目前提供了SolidWorks转URDF的插件,叫做sw_urdf_exporter,从http://wiki.ros.org/sw_urdf_exporter下载sw2urdfSetup.exe文件,下载后点击安装,安装完成后就能在solidworks中导出URDF模型了。 二、创建solidworks模型 下面以较为简单的四轮小车为例进行说...

weixin_45168199的博客 4万+

make和cmake区别

gcc是C语言编译器,而g++则是C++语言编译器,虽然gcc命令也可以用来编译C++语言的源码,但是它最终是要调用g++的。 make工具通过你提供的一个名为Makefile的文件,根据Makefile的内容来决定如何编译源文件。而关于make和cmake的区别, 你可以理解为make需要使用Makefile,而cmake是产生Makefile的工具。 qmake是Qt提供的一个编译工具,他可以...

yangwangxingkongcld的博客 2844

advanced installer 打包Flutter的Windows程序安装包(基本打包、开机自启、定时自动检测升级、包含卸载程序)

advanced installer 打包Flutter的Windows程序安装包(基本打包、开机自启、定时自动检测升级、包含卸载程序)

qq_45634989的博客 2876

C/C++学习笔记 CMake 与 Make有什么区别?

编译器是一种将源代码翻译成机器码的程序。代码的编译包括几个步骤,包括预处理、编译和链接,以创建可在其目标计算机上直接运行的库或可执行文件。​ 这个编译过程也称为构建过程,这是 CMake 和Make发挥作用的地方。​CMake 和 Make 之间的主要区别之一是 CMake 创建的输出可供 Make 等构建系统使用。这意味着 CMake 充当其他构建系统的生成器,并不负责实际编译。相比之下,Make 的输出是可以在目标计算机上执行的已编译二进制文件。

学以致用 知行合一 4702

华为OD机考双机位C卷 - 信道分配(Java & Python& JS & C/C++ & GO )

华为OD机考双机位C卷 - 信道分配

算法大师! 449

2026年全国青少年信息素养大赛算法应用主题赛(C++赛项初赛模拟卷1及答案解析)

2026年全国青少年信息素养大赛算法应用主题赛(C++赛项初赛模拟卷1及答案解析)

王老师青少年编程 2018

CMake和Make之间的区别-学习

CMake和Make之间的区别 - - 博客频道 - youkuaiyun.com http://blog.youkuaiyun.com/android_ruben/article/details/51698498

Sunshine_Dawn的博客 1388

【SAP HANA 24】HANA与Oracle SQL语法对照表

HANA SQL参考及Oracle 语法对照

探索 Java 编程的技巧、最佳实践和解决方案。本博客提供针对 Java 开发者的实用指南,涵盖从基础到高级话题,旨在提升编程效率和技能。 1421

gcc cmake make 之间的区别和联系

(3)但是makefile文件的编写非常复杂,同时不具有可移植性,也就是说你的项目换一个环境你就需要再重新编写一次makefile,因此又引出了cmake工具和cmakelist文件,cmake工具就是按照cmakelist中编写的内容来生成makefile文件的。(2)但对于项目中包含多个源文件时,直接编译就会产生混乱,因此我们需要一个东西来维持编译和链接的顺序和规则,这就用到了makefile文件和make工具,make工具就是按照makefile中规定的内容来对项目进行编译和链接的。

m0_64067123的博客 834

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

android studio make build区别,在Android studio工程中,CMake和NDK之间的区别

要清除这里的一些混乱:ndk-build是NDK中包含的构建系统.它使用Android.mk文件. NDK本身是为Android构建C/C++代码所需的编译器和库的集合. ndk-build和cmake都使用NDK.What is the actual difference between CMake and NDK build in android studio project.他们使用不同的语...

weixin_32678995的博客 389

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

android studio make build区别,android - android studio项目中CMake和NDK-build之间的区别 - 堆栈内存溢出...

我试图给出一些解释,以确定CMake和NDK-Build和设置之间的不同:一些初步说明:Android Studio的本机库默认构建工具是CMake。Android Studio还支持ndk-build,因为大量现有项目使用构建工具包来编译其本机代码。如果要创建新的本机库,则应使用CMake。由于存在大量遗留项目,因此包括对ndk-build的支持。CMake的:与Gradle一起工作的外部构建工...

weixin_28949779的博客 370

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

make, makefile, cmake, qmake 有何区别?

make, makefile, cmake, qmake 有何区别

chencichang的博客 8658

[CMake] cmake入门

CMake 跨平台的开源构建工具。cmake可以根据CmakeLists.txt文件指定生成器而生成相应的构建系统文件,比如Makefile,Ninja,Visual Studio项目文件等。因此开发者只需编写一个 CMakeLists.txt 文件,就可以在不同的操作系统和编译器上构建项目。简单来说CMake和make的区别就行,Cmake主要用于生成构建系统的文件,而Make则是实际执行构建的过程。并且Cmake也更加灵活,编写起来也更加容易。

qq_45280097的博客 1169

cmake(一)编译安装

一 基于x86的Centos7.7安装 ① 操作系统默认安装的 说明: 有两个'版本' ② 安装新版本 备注: 使用'新'特性 官网下载地址 参考博客 make和cmake的区别 B站cmake学习视频

wzj_110的博客 2243

☻CMake Q&A

cmake命令与make命令的执行过程原理是怎样的,有什么区别?

itzyjr的专栏 299

make、makefile、cmake及相关内容

最近在学gn和ninja,设计到了makefile相关的内容,相关概念有些记不太清楚了,重新查阅了一下,顺便留个笔记方便以后查看。 开始的时候先简单介绍一下程序的生命周期,源码到可执行程序,一般需要经过四个过程: 上图截取自《深入理解计算机系统》,图中说明了,一个程序要从源文件变为一个可执行的机器文件,需要至少四个步骤(python之类的语言还有一个解释过程)。 举个简单的例子,我们要在屏幕上面打印一句“hello world!”,除去编辑的过程,源文件先要经过预处理得到*.i文件,然后经过编译得到*.s

Z_Paper的博客 375

catkin_make_isolated 介绍

在PC ubuntu16.04环境下, 利用命令catkin_make 编译 hector_slam 时,报错如下: CMake Error at /opt/ros/kinetic/share/catkin/cmake/catkin_workspace.cmake:95 (message): This workspace contains non-catkin packages in it, and catkin cannot build a non-homogeneous workspace withou

weixin_42204587的博客 6825

cmake(三十七)Cmake执行其它命令

一 几个比较重要的模块 二 执行shell命令的几种方式 +++++++++++++++'重点'+++++++++++++++ 1)add_custom_command 2)add_custom_target 3)execute_process 备注: 执行'时机'不一样-->最后是'cmake时候'执行;前'两种'是make时候'可能'执行(依据:是否指定ALL或者make的时候'是否指定'target) 4)ExternalProject 备注: 在使用'Exte...

wzj_110的博客 1186

cmake和makefile区别和cmake指定编译器(cmake -G)

其实很多公司和项目就是直接使用make的,但make代码规则严格,语法过于复杂,在做跨平台和跨编译器时的管理更加复杂,移植到不同环境的成本过大。首先cmake是项目构建生成工具,cmake的代码可以与平台系统和编译器无关。makefile 可以理解为是make工具使用的代码,make读取makefile中的配置信息来实现编译、链接和部署。工具” 只是使用这些工具其实就能够编译出所有的目标,但由于命令过于复杂,编译的流程不好控制。也就是说cmake是用来生成makefile和其他项目生成工具配置的。

爱她就要努力 927
上一篇: [J2EE]实现一个最简单的基于Servlet的web程序
下一篇: [Android]Android中人脸识别接口的使用
android_ruben
博客等级 码龄11年 106粉丝 166原创
评论 11
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值