c++ - CMake第三方库安装

标签 c++ cmake

我是编程新手。对于我的学习项目,我需要安装第三方库以与 CMake ( GitHub project ) 一起使用。

我在我的电脑上使用 Arch OS。通常我在以下位置构建所有非存储库包:~/aur。 CMake 版本为 3.17。

然后我尝试根据说明构建一个库:

...
cmake --config Debug "-DCMAKE_BUILD_TYPE=Debug" ..

这让我犯了一个错误:

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
PNG_INCLUDE_DIR
   used as include directory in directory /home/wizki/aur/P0267_RefImpl/P0267_RefImpl/Tests

-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.

如果我忽略这个错误并使用以下方法构建这个库:

cmake --build .

搭建成功,但是在我的项目搭建过程中出现错误:

CMake Error at CMakeLists.txt:15 (find_package):
  By not providing "Findio2d.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "io2d", but
  CMake did not find one.

Could not find a package configuration file provided by "io2d" with any of
  the following names:

    io2dConfig.cmake
    io2d-config.cmake

Add the installation prefix of "io2d" to CMAKE_PREFIX_PATH or set
"io2d_DIR" to a directory containing one of the above files.  If "io2d"
provides a separate development package or SDK, be sure it has been
installed.

-- Configuring incomplete, errors occurred!

经过网络搜索后,我尝试了这个解决方案:Daniweb . 安装了 libpng 和 zlib 包; FindPNG.cmake 存在于/usr/share/cmake-3.17/Modules/。 但是我的$CMAKE_INCLUDE_PATH$CMAKE_LIBRARY_PATH 是空的:

[wizki@evix Debug]$ echo $CMAKE_INCLUDE_PATH

[wizki@evix Debug]$ echo $CMAKE_LIBRARY_PATH

我试图在 FindPNG.cmake 中搜索路径,但没有结果。来自 CMake wiki我想库路径之一是 /usr/lib。我曾尝试在内部构建一个库,但我遇到了同样的问题。

接下来我可以尝试什么?

最佳答案

假设您正在为 Udacity 上的 C++ 纳米学位项目学习。我遇到了同样的问题,我发现在终端中执行以下命令后安装 IO2D

cmake --build . 

执行以下命令

sudo make install

这会将必要的文件复制到 Cmake 可以找到的地方。

因此,完整的流程是这样的

git clone --recurse-submodules https://github.com/cpp-io2d/P0267_RefImpl
cd P0267_RefImpl
mkdir Debug
cd Debug
cmake --config Debug "-DCMAKE_BUILD_TYPE=Debug" ..
cmake --build .
sudo make install

我在这里找到了解决方案 - https://github.com/udacity/CppND-Route-Planning-Project/issues/1#issuecomment-569472612

PS:由于您是编程新手,我想分享一个提示,很多时候其他人也有同样的问题,并且在 GitHub 存储库的“问题”选项卡中更容易找到解决方案。

关于c++ - CMake第三方库安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61025954/

相关文章:

c++ - 为复杂数据结构重载 [] C++ 运算符

c++ - Clang-Format:如何在 switch 语句中获取单行 case 语句

c++ - MAC 操作系统 : dynamically linked library not found despite correct rpath

c++ - 如何避免每次编译时都必须键入 -std=c++11

Cmake - 更改外部项目的 lib 和包含目录的位置以及正确的链接

cmake - 如何在 CMake 文件中添加头文件路径

c++ - 尝试使用 friend 时出错

android - 通过命令行(Makefile)手动创建android apk

c++ - 为什么这个指向 vector 中有效 int 的指针未定义?

c++ - 将 CMake 与 LLVM 一起使用时出错