C++ 我如何使用 CMake?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7859623/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I use CMake?
提问by lital maatuk
I am trying to use CMake in order to compile opencv.
我正在尝试使用 CMake 来编译 opencv。
I am reading the tutorialbut can't understand what is CMakeLists files and how is it connected to the gui of CMake?
我正在阅读教程,但不明白什么是 CMakeLists 文件以及它如何连接到 CMake 的 gui?
Also couldn't understand what are makefiles, are they the same is CMakeLists?
也无法理解什么是 makefile,它们是否与 CMakeLists 相同?
And which file is it which I in the end open with visual-studio?
最后我用visual-studio打开的是哪个文件?
采纳答案by holtavolt
CMake takes a CMakeList file, and outputs it to a platform-specific build format, e.g. a Makefile, Visual Studio, etc.
CMake 获取 CMakeList 文件,并将其输出为特定于平台的构建格式,例如 Makefile、Visual Studio 等。
You run CMake on the CMakeList first. If you're on Visual Studio, you can then load the output project/solution.
您首先在 CMakeList 上运行 CMake。如果您使用的是 Visual Studio,则可以加载输出项目/解决方案。
回答by Basile Starynkevitch
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)
我不了解 Windows(从未使用过),但在 Linux 系统上,您只需要创建一个构建目录(在顶级源目录中)
mkdir build-dir
go inside it
进去
cd build-dir
then run cmake
and point to the parent directory
然后运行cmake
并指向父目录
cmake ..
and finally run make
最后运行 make
make
Notice that make
and cmake
are different programs. cmake
is a Makefile
generator, and the make
utility is governed by a Makefile
textual file. See cmake& makewikipedia pages.
请注意,make
和cmake
是不同的程序。cmake
是一个Makefile
生成器,该make
实用程序由一个Makefile
文本文件管理。请参阅 cmake和制作维基百科页面。
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)
注意:在 Windows 上,cmake
可能会运行,因此可能需要以不同的方式使用。您需要阅读文档(就像我为 Linux 所做的那样)
回答by Basile Starynkevitch
Yes, cmakeand makeare different programs. cmake
is (on Linux) a Makefilegenerator (and Makefile-s are the files driving the make
utility). There are other Makefilegenerators (in particular configure and autoconf etc...). And you can find other build automationprograms (e.g. ninja).
是的,cmake和make是不同的程序。cmake
是(在 Linux 上)一个Makefile生成器(而Makefile-s 是驱动该make
实用程序的文件)。还有其他Makefile生成器(特别是 configure 和 autoconf 等...)。您还可以找到其他构建自动化程序(例如ninja)。
回答by George Theodosiou
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.
关于 CMake 3.13.3、Windows 平台和 IDE Visual Studio 2017,我建议使用本指南。简而言之,我建议:
1. 下载 cmake > 解压 > 执行。
2. 例如下载 GLFW > 解压 > 在Build文件夹内创建。
3.在cmake中浏览“源”>浏览“构建”>配置和生成。
4. 在 Visual Studio 2017 中构建您的解决方案。
5. 获取二进制文件。
问候。