如何使用 CMake?
我正在尝试使用 CMake 来编译 opencv。
我正在阅读 教程 但无法理解什么是 CMakeLists 文件以及它如何连接到CMake 的图形用户界面?
也无法理解什么是makefile,它们与CMakeLists相同吗?
我最终用 Visual-studio 打开哪个文件?
I am trying to use CMake in order to compile opencv.
I am reading the tutorial but can't understand what is CMakeLists files and how is it connected to the gui of CMake?
Also couldn't understand what are makefiles, are they the same is CMakeLists?
And which file is it which I in the end open with visual-studio?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我不了解 Windows(从未使用过它),但在 Linux 系统上,您只需创建一个构建目录(在顶级源目录中)
进入其中,
然后运行
cmake
并指向父目录,最后运行
make
请注意,
make
和cmake
是不同的程序。cmake
是一个Makefile
生成器,而make
实用程序由Makefile
文本文件控制。请参阅 cmake & 制作维基百科页面。注意:在 Windows 上,
cmake
可能会运行,因此可能需要以不同的方式使用。你需要阅读文档(就像我对 Linux 所做的那样)I don't know about Windows (never used it), but on a Linux system you just have to create a build directory (in the top source directory)
go inside it
then run
cmake
and point to the parent directoryand finally run
make
Notice that
make
andcmake
are different programs.cmake
is aMakefile
generator, and themake
utility is governed by aMakefile
textual file. See cmake & make wikipedia pages.NB: On Windows,
cmake
might operate so could need to be used differently. You'll need to read the documentation (like I did for Linux)CMake 获取 CMakeList 文件,并将其输出为特定于平台的构建格式,例如 Makefile、Visual Studio 等。
首先在 CMakeList 上运行 CMake。如果您使用的是 Visual Studio,则可以加载输出项目/解决方案。
CMake takes a CMakeList file, and outputs it to a platform-specific build format, e.g. a Makefile, Visual Studio, etc.
You run CMake on the CMakeList first. If you're on Visual Studio, you can then load the output project/solution.
是的,cmake 和 make 是不同的程序。
cmake
是(在 Linux 上)Makefile 生成器(Makefile-s 是驱动make
实用程序的文件) 。还有其他Makefile生成器(特别是configure和autoconf等...)。您还可以找到其他构建自动化程序(例如忍者)。Yes, cmake and make are different programs.
cmake
is (on Linux) a Makefile generator (and Makefile-s are the files driving themake
utility). There are other Makefile generators (in particular configure and autoconf etc...). And you can find other build automation programs (e.g. ninja).CMake(跨平台制作)是一个构建系统生成器。它不会构建您的源代码,而是生成构建系统所需的内容:构建脚本。这样做您不需要编写或维护特定于平台的构建文件。 CMake 使用相对较高级别的 CMake 语言,通常编写为
CMakeLists.txt
文件。使用第三方库时的一般工作流程通常归结为以下命令:第一行称为配置步骤,这会在您的系统上生成构建文件。
-S
(ource) 是库源,-B
(uild) 文件夹。 CMake 根据您的系统回退生成构建。在 Windows 上它将是 MSBuild,在 Linux 上将是 GNU Makefiles。您可以使用-G
(enerator) 参数指定构建,例如:此步骤结束时,生成构建脚本,例如 Makefile、*.sln 构建目录中的文件等。
第二行调用实际的构建命令,就像在构建文件夹上调用
make
一样。第三行安装库。如果您使用的是 Windows,则可以通过
cmake --open build
快速打开生成的项目。现在,您可以在项目中使用由 CMake 配置的已安装库,编写您自己的 CMakeLists.txt 文件。为此,您需要创建一个目标并使用
find_package
命令查找您安装的包,该命令将导出库目标名称,并将它们链接到您自己的目标。CMake (Cross platform make) is a build system generator. It doesn't build your source, instead, generates what a build system needs: the build scripts. Doing so you don't need to write or maintain platform specific build files. CMake uses relatively high level CMake language which usually written in
CMakeLists.txt
files. Your general workflow when consuming third party libraries usually boils down the following commands:The first line known as configuration step, this generates the build files on your system.
-S
(ource) is the library source, and-B
(uild) folder. CMake falls back to generate build according to your system. it will be MSBuild on Windows, GNU Makefiles on Linux. You can specify the build using-G
(enerator) paramater, like:end of the this step, generates build scripts, like Makefile, *.sln files etc. on build directory.
The second line invokes the actual build command, it's like invoking
make
on the build folder.The third line install the library. If you're on Windows, you can quickly open generated project by,
cmake --open build
.Now you can use the installed library on your project with configured by CMake, writing your own CMakeLists.txt file. To do so, you'll need to create a your target and find the package you installed using
find_package
command, which will export the library target names, and link them against your own target.从 Windows 终端进行 Cmake:
Cmake from Windows terminal:
关于 CMake 3.13.3、平台 Windows 和 IDE Visual Studio 2017,我建议使用此指南。简而言之,我建议:
1.下载cmake>解压缩>执行它。
2. 以下载GLFW为例>解压缩>在文件夹 Build 中创建。
3. 在cmake中浏览“源”>浏览“构建”>配置并生成。
4. 在 Visual Studio 2017 中构建您的解决方案。
5. 获取二进制文件。
问候。
Regarding CMake 3.13.3, platform Windows, and IDE Visual Studio 2017, I suggest this guide. In brief I suggest:
1. Download cmake > unzip it > execute it.
2. As example download GLFW > unzip it > create inside folder Build.
3. In cmake Browse "Source" > Browse "Build" > Configure and Generate.
4. In Visual Studio 2017 Build your Solution.
5. Get the binaries.
Regards.