Cmake,gnu make和手动编译之间的区别 [英] Difference between Cmake, gnu make and manually compiling

查看:162
本文介绍了Cmake,gnu make和手动编译之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编程新手,所以这比技术问题更多是抽象问题.我一直在使用IDE进行学习,但听说它们在创建可执行文件时会过分简化编译,组装和链接的过程.

I'm new to programming so this is a more of a abstract question than a technical one. I've been using IDE's to learn but I heard they tend to oversimplify the act of compiling,assembling and linking when creating an executable file.

我试图下载和编译一个不依赖IDE的库(在本例中为librocket).我首先必须使用Cmake来创建二进制文件.配置和生成后,在输出目录中没有看到任何目标文件或.cpp文件.然后,我不得不使用gnu make命令,然后在输出目录中创建目标文件和.cpp文件.

I'm trying to download and compile a library without relying on an IDE (in this case librocket). I first had to use Cmake to create the binaries. After configuring and generating, I didn't see any object files or .cpp files in the output directory. I then had to use the gnu make command which then created both object files and .cpp files in the output directory.

Cmake和gnu make从下载源代码到实际创建目标文件有哪些步骤?编译器和链接器实际上在什么时候被调用?

What steps from downloading the source code to actually creating the object files does Cmake and gnu make do? At what point is the compiler and linker actually called?

我已经成功编译了我编写的测试库,然后编译了另一个使用g ++链接到它的程序,但是我有点迷失了,因为我必须使用Cmake和gnu make而不是直接调用编译器.

I've successfully compiled a test library I wrote and then compiled another program that linked to it using g++ but I'm kind of lost because I have to use Cmake and gnu make instead of calling a compiler directly.

推荐答案

Cmake是一个项目生成器".它实际上并没有建立任何目标文件等.它的作用是为其他工具(例如GNU make)生成控制文件,这些文件将生成目标文件等.

Cmake is a "project generator". It doesn't actually build any object files etc.; what it does is generate the control files for other tools (such as GNU make) which will build object files, etc.

使用cmake而不是直接编写makefile的优点是,使用相同的cmake输入文件,cmake可以为各种不同的构建控制工具生成项目文件:除了makefile之外,它还可以生成Xcode(Mac OS X)项目文件,Microsoft Visual Studio项目文件以及其他工具(如Ninja)的控制文件.如果您要编写需要在许多不同平台上构建的软件,那么cmake通常是一个不错的选择.

The advantage of using cmake instead of writing the makefile directly is that, using the same cmake input file, cmake can generate project files for all sorts of different build control tools: in addition to makefiles it can generate Xcode (Mac OS X) project files, Microsoft Visual Studio project files, and control files for other tools like Ninja. If you're writing software that needs to be built on lots of different platforms then cmake is often a good choice.

对于您的情况,它是这样的:cmake生成一组makefile(仅).通常,只有在工作空间干净的情况下,才执行一次此操作.然后运行make,当各种文件发生更改时,make将根据需要使用这些makefile调用编译器.如果任何cmake输入文件发生更改,makefile也具有重新运行cmake本身的规则.

For your situation, it goes like this: cmake generates a set of makefiles (only). You typically only do this once when you have a clean workspace. Then you run make which uses those makefiles to invoke the compiler as needed, when various files change. The makefiles also have rules to re-run cmake itself if any of the cmake input files change.

这篇关于Cmake,gnu make和手动编译之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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