gpt4 book ai didi

c++ - 如何构建 Armadillo C++ 库以在非标准位置静态链接到 OpenBLAS

转载 作者:行者123 更新时间:2023-11-28 05:45:41 25 4
gpt4 key购买 nike

我正在尝试构建 Armadillo C++ 库(6.6 版),它确实构建良好。然而,我的问题是我已经单独下载了 OpenBLAS 的源代码并构建了它。我希望 Armadillo 使用我在本地构建的 OpenBLAS,并且我希望它将它静态链接到生成的 Armadillo 库中。

所以,

  1. 如何告诉 Armadillo CMake 使用特定的 OpenBLAS?
  2. 我如何告诉 Armadillo CMake 静态链接上述 OpenBLAS,以便它生成一个包含我的 OpenBLAS 的 libarmadillo?

最佳答案

如果您从源代码安装了 OpenBLAS,它位于非标准位置(对我来说是/opt/OpenBLAS)并且具有非标准名称 (OpenBLAS)。因此cmake很难找到它,以解决问题请编辑 your_sources_dir/cmake_aux/Modules/ARMA_FindOpenBLAS.cmake 中的文件,如下所示:

set(OpenBLAS_NAMES)
set(OpenBLAS_NAMES ${OpenBLAS_NAMES} openblaso)
set(OpenBLAS_NAMES ${OpenBLAS_NAMES} openblasp)
set(OpenBLAS_NAMES ${OpenBLAS_NAMES} openblas )
set(OpenBLAS_NAMES ${OpenBLAS_NAMES} OpenBLAS )

set(OpenBLAS_TMP_LIBRARY)
set(OpenBLAS_TMP_LIBRARIES)


foreach (OpenBLAS_NAME ${OpenBLAS_NAMES})
find_library(${OpenBLAS_NAME}_LIBRARY
NAMES ${OpenBLAS_NAME}
PATHS ${CMAKE_SYSTEM_LIBRARY_PATH} /lib64 /lib /usr/lib64 /usr/lib /usr/local/lib64 /usr/local/lib /opt/local/lib64 /opt/local/lib /opt/OpenBLAS/lib
)

set(OpenBLAS_TMP_LIBRARY ${${OpenBLAS_NAME}_LIBRARY})

if(OpenBLAS_TMP_LIBRARY)
set(OpenBLAS_TMP_LIBRARIES ${OpenBLAS_TMP_LIBRARIES} ${OpenBLAS_TMP_LIBRARY})
endif()
endforeach()


# use only one library

if(OpenBLAS_TMP_LIBRARIES)
list(GET OpenBLAS_TMP_LIBRARIES 0 OpenBLAS_LIBRARY)
endif()


if(OpenBLAS_LIBRARY)
set(OpenBLAS_LIBRARIES ${OpenBLAS_LIBRARY})
set(OpenBLAS_FOUND "YES")
else()
set(OpenBLAS_FOUND "NO")
endif()


if(OpenBLAS_FOUND)
if (NOT OpenBLAS_FIND_QUIETLY)
message(STATUS "Found OpenBLAS: ${OpenBLAS_LIBRARIES}")
endif()
else()
if(OpenBLAS_FIND_REQUIRED)
message(FATAL_ERROR "Could not find OpenBLAS")
endif()
endif()


# mark_as_advanced(OpenBLAS_LIBRARY)

然后使用 cmake 进行 Armadillo 的常规安装。

希望这个建议对您有所帮助。

关于c++ - 如何构建 Armadillo C++ 库以在非标准位置静态链接到 OpenBLAS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36266242/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com