了解CMake,make和GCC的角色 [英] Understanding roles of CMake, make and GCC

查看:94
本文介绍了了解CMake,make和GCC的角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1。 cmake 是CMake软件的命令:为构建自动化系统做准备; make和make install是来自Make软件的命令:构建自动化系统。

1. cmake is a command from CMake software: preparation for build automation system; make and make install are commands from Make software: build automation system.

2。。阅读此帖子,据我了解是:

2. From reading this post, what I understand is that:

a。。这种 makemake的东西实际上在其实现中使用g ++ / gcc。 cmake和make东西基本上只是使用g ++ / gcc的工具。

a. This "cmake and make" stuffs actually use g++ / gcc in its implementation. cmake and make stuffs are basically just tools in using g++ / gcc. Is that correct?

b。 gcc / g ++是执行实际工作的编译器。

b. gcc / g++ are the compiler that do the actual work.

c。因此,我可以直接使用gcc / g ++而不使用make和CMake东西吗?

c. So I can just use gcc / g++ directly without using the make and CMake things?

3 。根据此stackoverflow answer :CMake需要一个CMakeList.txt文件,并将其输出为特定于平台的构建格式,例如Makefile,Visual Studio等。

3. According to this stackoverflow answer: CMake takes a CMakeList.txt file, and outputs it to a platform-specific build format, e.g., a Makefile, Visual Studio, etc.

但是当我遇到 openCV安装:

However when I came across this openCV installation :

mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

它在没有CMakeLists.txt文件的目录中执行cmake命令。您可以对此进行解释和阐述吗?

It executes cmake command in a directory where there is no CMakeLists.txt file. Can you explain and elaborate on this?

4。。我见过的通常步骤是: cmake make sudo make install
我读了这个stackoverflow post ,据我所知:

4. The usual steps that I've seen are: cmake, make, sudo make install. I read this stackoverflow post, what I understand:

(i) make 用于构建项目。

(ii) make install 是将二进制文件/可执行文件复制到已安装的文件中目录。

(ii) make install is to copy the binary / executables to the installed directories.

a。因此,当我们 make 时,结果/二进制在哪里?文件/可执行文件存储在?

a. So when we make, where are the result / binary files / executables stored at?

b。如果我们仅运行 make 而没有进行安装,是否表示未生成文件?

b. If we only run make without make install, does it mean that the files are not generated?

c。碰到过这个openCV 教程在GCC和CMake上使用openCV。它使用:

c. I came across this openCV tutorial on using openCV with GCC and CMake. It uses:

cd <DisplayImage_directory>
cmake .
make

为什么不做 make install

5。摘要:


  • CMake使用CMakeList.txt文件(跨平台)生成Makefile(特定于平台)。

  • CMake takes CMakeList.txt file (which is cross platform) to generate a Makefile (which is specific to a platform).

我可以手动编写Makefile并跳过CMake步骤。但是最好使用CMake步骤,因为它是跨平台的,否则如果更改平台,我必须再次重写Makefile。

I can just write Makefile manually and skip the CMake step. but it is better to do with the CMake step because it is cross platform, otherwise I have to rewrite the Makefile again if I change platform.

Make需要Makefile (由CMake生成或手动编写)作为编译和构建的指南。 Make在其工作中主要使用gcc / g ++或其他编译器。 Make本身只是编译器的工具。

Make takes Makefile (which is generated by CMake or written manually) as a guide to compile and build. Make basically uses gcc / g++ or other compiler in its work. Make itself is just a tool for the compiler.

进行安装将结果/可执行文件放入安装路径

Make install put the result / executables into the install path

推荐答案

CMake为其他构建系统生成文件。这些可以是诸如Visual Studio或Eclipse之类的IDE的Makefile,Ninja文件或项目文件。生成文件包含对GCC,Clang或cl.exe等编译器的调用。如果安装了多个编译器,则可以选择一个。

这三个部分都是独立的。编译器,构建系统和CMake。

CMake generates files for other build systems. These can be Makefiles, Ninja files or projects file for IDEs like Visual studio or Eclipse. The build files contains calls to compilers like GCC, Clang or cl.exe. If you have several compilers installed, you can choose one.
All three parts are independent. The compiler, the build system and CMake.

有了历史记录,就更容易理解。人们使用他们的编译器。随着时间的流逝,添加了太多的标志,以至于每次都键入它们很麻烦。因此,将调用放入脚本中。从那时起,构建系统(Make,Ninja)得到了发展。

人们想要支持多个平台,编译器,方案等,并且构建系统文件变得难以维护,并且使用起来容易出错。这就是人们发明了为实际构建系统创建文件的元构建系统的原因。例子是Autotools或CMake。

It is easier to understand, when you have the history. People used their compiler. Over the time the added so many flags, that it was cumbersome to type them every time. So the put the calls in a script. From that the build systems (Make, Ninja) evolved.
The people wanted to support multiple platforms, compilers, scenarios and so on and the build system files became hard to maintain and their use was error-prone. That's the reason people invented meta build system that create the files for the actual build system. Examples are Autotools or CMake.



  1. CMake不使用编译器,make不使用编译器实现。但是会调用(使用)编译器。

  2. CMakeLists.txt文件应位于 release 的父目录中。 CMake调用的最后一个参数指示CMakeLists.txt文件所在的路径。

  3. 正确,make在生成目录中生成文件。在示例3中。版本是构建目录。您可以找到所有生成的文件并使用它们。安装是可选的,尤其是如果您要开发软件时,就不需要安装它。

  4. 尝试为大型项目编写Makefile,您将看到它有多少工作。但是,是的,5中的所有内容都是正确的。

  1. Yes
  2. CMake does not use your compiler, make does not implement it, but it calls (uses) the compiler.
  3. The CMakeLists.txt file should be in the parent directory of release. The last argument of the CMake call indicates the path were the CMakeLists.txt file is located.
  4. Right, make generates the file in the build directory. In your example from 3. release is the build directory. You can find all the generated files and use them. Installing is optional, especially if you want to develop the software, you are not installing it.
  5. Try writing Makefiles for a large project and you will see how much work it is. But yes, everything in 5 is right.

这篇关于了解CMake,make和GCC的角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆