如何使用 CMake?

发布于 2024-12-11 11:36:17 字数 241 浏览 0 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

瀟灑尐姊 2024-12-18 11:36:17

我不了解 Windows(从未使用过它),但在 Linux 系统上,您只需创建一个构建目录(在顶级源目录中)

mkdir build-dir

进入其中,

cd build-dir

然后运行 ​​cmake 并指向父目录

cmake ..

,最后运行 make

make

请注意,makecmake 是不同的程序。 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)

mkdir build-dir

go inside it

cd build-dir

then run cmake and point to the parent directory

cmake ..

and finally run 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 & 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)

青朷 2024-12-18 11:36:17

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.

ˉ厌 2024-12-18 11:36:17

是的,cmakemake 是不同的程序。 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 the make utility). There are other Makefile generators (in particular configure and autoconf etc...). And you can find other build automation programs (e.g. ninja).

猫弦 2024-12-18 11:36:17

CMake(跨平台制作)是一个构建系统生成器。它不会构建您的源代码,而是生成构建系统所需的内容:构建脚本。这样做您不需要编写或维护特定于平台的构建文件。 CMake 使用相对较高级别的 CMake 语言,通常编写为CMakeLists.txt 文件。使用第三方库时的一般工作流程通常归结为以下命令:

cmake -S thelibrary -B build
cmake --build build
cmake --install build

第一行称为配置步骤,这会在您的系统上生成构建文件。 -S(ource) 是库源,-B(uild) 文件夹。 CMake 根据您的系统回退生成构建。在 Windows 上它将是 MSBuild,在 Linux 上将是 GNU Makefiles。您可以使用 -G(enerator) 参数指定构建,例如:

cmake -G Ninja -S libSource -B build

此步骤结束时,生成构建脚本,例如 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:

cmake -S thelibrary -B build
cmake --build build
cmake --install build

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:

cmake -G Ninja -S libSource -B build

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.

情愿 2024-12-18 11:36:17

从 Windows 终端进行 Cmake:

mkdir build
cd build/
cmake ..
cmake --build . --config Release
./Release/main.exe

Cmake from Windows terminal:

mkdir build
cd build/
cmake ..
cmake --build . --config Release
./Release/main.exe
蓝咒 2024-12-18 11:36:17

关于 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文