cmake 未在 Conda 环境中检测库文件

cmake 未在 Conda 环境中检测库文件

我正在尝试使用 Geant 的 Conda 安装说明https://geant4-userdoc.web.cern.ch/UsersGuides/InstallationGuide/html/index.html#conda-on-linux-macos

# Basic steps to setup environment
conda create -c conda-forge --name <my-environment> geant4
conda activate <my-environment>

然后我使用以下命令编译其中一个示例,该命令抱怨缺少库文件:

~$ cmake ~/.conda/envs/geant4/share/Geant4/examples/basic/B1/
-- The C compiler identification is GNU 11.4.0
-- The CXX compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find EXPAT: Found unsuitable version "2.4.7", but required is at
  least "2.5.0" (found /usr/lib/x86_64-linux-gnu/libexpat.so)
Call Stack (most recent call first):
  /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:592 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake-3.22/Modules/FindEXPAT.cmake:65 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /home/user1/.conda/envs/geant4/lib/cmake/Geant4/Geant4Config.cmake:268 (find_dependency)
  CMakeLists.txt:13 (find_package)

-- Configuring incomplete, errors occurred!
See also "/home/user1/CMakeFiles/CMakeOutput.log".

从运行中conda list我可以看到所有模块及其各自的 library.so 文件都已安装到环境中。但从cmakeConda 环境中提取库文件却很困难。

我曾尝试将 Conda 环境添加到$LD_LIBRARY_PATH并在 cmake 文件中配置一行以明确查找~/.conda/envs/geant4/lib,但cmake仍然无法选择库目录并返回到主系统库目录。

CMakeLists.txt < add the following
set(CMAKE_INSTALL_RPATH "~/.conda/envs/geant4/lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

我不确定为什么cmake不考虑$LD_LIBRARY_PATH或强制执行 Geant4/B1 示例 CMake 文件中的库位置。

任何帮助都将非常有帮助,提前谢谢!

答案1

以下环境似乎可以完成这项工作。

设置CMAKE_PREFIX_PATH允许的 cmake 使用 Conda 环境提供的 include 和 lib 目录进行编译。

export CMAKE_PREFIX_PATH=/home/user1/.conda/envs/geant4/

相关内容