Conan安装的net-snmp包无法被CMake识别的问题求助
问题:CMake无法找到Conan引入的net-snmp包
创建了一个简单的Conan项目,希望在C++项目中引入Conan Center的net-snmp包(版本5.9.1),但使用CMake构建项目时无法找到该包。
复现步骤
- 从模板创建项目:
conan new hello/0.1 --template=cmake_exe - 在生成的
conanfile.py中添加requirements方法引入依赖:
完整的def requirements(self): # 仅添加了这两行 self.requires("net-snmp/5.9.1")conanfile.py代码如下:from conan import ConanFile from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout class HelloConan(ConanFile): name = "hello" version = "0.1" # 可选元数据 license = "<在此处填写包许可证>" author = "<在此处填写你的姓名> <在此处填写你的邮箱>" url = "<在此处填写包配方仓库地址,用于提交包相关问题>" description = "<在此处填写Hello项目的描述>" topics = ("<添加一些标签>", "<这里>", "<还有这里>") # 二进制配置 settings = "os", "compiler", "build_type", "arch" options = {"shared": [True, False], "fPIC": [True, False]} default_options = {"shared": False, "fPIC": True} # 源码与本配方位于同一目录,复制到配方中 exports_sources = "CMakeLists.txt", "src/*", "include/*" def requirements(self): # 仅添加以下两行 self.requires("net-snmp/5.9.1") def config_options(self): if self.settings.os == "Windows": del self.options.fPIC def layout(self): cmake_layout(self) def generate(self): tc = CMakeToolchain(self) tc.generate() def build(self): cmake = CMake(self) cmake.configure() cmake.build() def package(self): cmake = CMake(self) cmake.install() def package_info(self): self.cpp_info.libs = ["hello"] - 在
CMakeLists.txt中添加:find_package(net-snmp 5.9.1 REQUIRED)
执行构建命令
mkdir build && cd build conan install .. cmake ..
错误信息
CMake错误出现在CMakeLists.txt第4行(find_package):
由于未在CMAKE_MODULE_PATH中提供"Findnet-snmp.cmake",本项目要求CMake查找由"net-snmp"提供的包配置文件,但CMake未找到。未找到版本为5.9.1的"net-snmp"提供的包配置文件,该文件应具有以下名称之一:
net-snmpConfig.cmake net-snmp-config.cmake请将"net-snmp"的安装前缀添加到CMAKE_PREFIX_PATH中,或者将"net-snmp_DIR"设置为包含上述文件之一的目录。如果"net-snmp"提供单独的开发包或SDK,请确保已安装它。
使用环境
- Ubuntu 22.04.3
- Conan 1.60.2(因CI限制无法使用2.X版本)
- CMake 3.27.2
内容的提问来源于stack exchange,提问作者schande
相关产品推荐
相关产品推荐

