CMake 无法使用 find_package 找到 CryptoPP

问题描述 投票:0回答:2

我已经使用

sudo apt install libcrypto++-dev

安装了 C++ 库“Crypto++”

我使用以下命令找到lib:

find_package(CryptoPP REQUIRED)

但CMake由于某种原因找不到它,并打印此错误:

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

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

    CryptoPPConfig.cmake
    cryptopp-config.cmake

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

我也尝试了所有的名称,如 CryptoPP 等,但没有成功。

c++ cmake crypto++
2个回答
4
投票

三秒钟的谷歌搜索显示 CryptoPP 人员决定停止支持 CMake 本身。

社区支持的 CMake 构建内容现在位于这里。随着构建说明的进行,获取它,然后您可以将您的目标链接到

cryptopp

或者,您可以使用似乎随该软件包附带的 pkgconfig 文件试试运气:

find_package(PkgConfig REQUIRED)
pkg_check_modules(Cryptopp REQUIRED IMPORTED_TARGET libcrypto++)
target_link_libraries(your_application PUBLIC PkgConfig::Cryptopp)

0
投票

对于那些在使用第一个答案时遇到困难的人。 CMake 的一个可能解决方案,可在 Linux (

sudo apt-get install libcrypto++-dev libcrypto++-doc libcrypto++-utils
) 和 MacOS (
brew install cryptopp
) 上运行:

find_path(CRYPTOPP_INCLUDE cryptopp/cryptlib.h /usr/include /usr/local/include /opt/homebrew/include)
find_library(CRYPTOPP_LIB cryptopp /usr/lib /usr/local/lib /opt/homebrew/lib)
if(NOT CRYPTOPP_INCLUDE OR NOT CRYPTOPP_LIB)
    message(FATAL_ERROR "Crypto++ library is not found!")
endif()

add_executable(Target ...)

target_link_libraries(Target PRIVATE ${CRYPTOPP_LIB})
target_include_directories(Target PRIVATE ${CRYPTOPP_INCLUDE})
© www.soinside.com 2019 - 2024. All rights reserved.