gpt4 book ai didi

c++ - 如何在 CMake 中将 OpenBLAS 定义为子目录?

转载 作者:行者123 更新时间:2023-12-03 20:39:40 35 4
gpt4 key购买 nike

我正在使用OpenBLAS我的 BLASLAPACK例行通话。我不想要我的 C++ 的用户群库必须在他们的机器上安装依赖项。所以我想提供OpenBLAS我的图书馆 third_party并有 CMake在本地链接到它。
那个树
这是这个最小示例项目的树。

OBLASCmake/
├─ third_party/
│ ├─ OpenBLAS-0.3.15
├─ CMakeLists.txt
├─ main.cpp

主程序
#include <iostream>
#include <vector>

using namespace std;

extern "C" double ddot_(int *n, double *x, int *incx, double *y, int * incy);

int main() {
int n = 3; // n elements
vector<double> x = {1.2, 2.4, 3.8};
vector<double> y = {4.8, 5.5, 6.2};
int incx = 1; // increments
int incy = 1;

double dot_product = ddot_(&n, &*x.begin(), &incx, &*y.begin(), &incy);

std::cout << dot_product << std::endl;
return 0;
}
CMakeLists(当前)
这将进入系统并查找 OpenBLAS安装在用户机器上。这不是我想要的,但它对我有用,因为我在我的机器上安装了它。
cmake_minimum_required(VERSION 3.19)
project(OBLASCMake)

set(CMAKE_CXX_STANDARD 11)

add_library(OBLASCMake SHARED main.cpp)
set(BLA_VENDOR OpenBLAS)
find_package(BLAS)
if (BLAS_FOUND)
target_link_libraries(OBLASCMake ${BLAS_LIBRARIES})
else()
# ERROR
endif()

add_executable(test1 main.cpp)
target_link_libraries(test1 OBLASCMake)
enable_testing()
add_test(NAME RunTest COMMAND ${CMAKE_BINARY_DIR}/test1)
使用此 cmake 运行测试的结果是 42.52 的输出作为两个 vector 的点积。
CMakeLists(我想要的)
这种定义本地安装的方法不能正常工作。
cmake_minimum_required(VERSION 3.19)
project(OBLASCMake)

set(CMAKE_CXX_STANDARD 11)

add_library(OBLASCMake SHARED main.cpp)
# cant use add_subdirectory and find_package
# add_subdirectory(third_party/OpenBLAS-0.3.15)
set(OpenBLAS_DIR ${CMAKE_SOURCE_DIR}/third_party/OpenBLAS-0.3.15)
find_package(OpenBLAS REQUIRED HINTS ${CMAKE_SOURCE_DIR}/third_party/OpenBLAS-0.3.15)

add_executable(test1 main.cpp)
target_link_libraries(test1 OBLASCMake)
enable_testing()
add_test(NAME RunTest COMMAND ${CMAKE_BINARY_DIR}/test1)
使用 CMake 构建会导致以下错误消息:
CMake Error at CMakeLists.txt:12 (find_package):
Could not find a package configuration file provided by "OpenBLAS" with any
of the following names:

OpenBLASConfig.cmake
openblas-config.cmake

Add the installation prefix of "OpenBLAS" to CMAKE_PREFIX_PATH or set
"OpenBLAS_DIR" to a directory containing one of the above files. If
"OpenBLAS" provides a separate development package or SDK, be sure it has
been installed.
有一个 OpenBLASConfig.cmake third_party/OpenBLAS-0.3.15/ 中的文件,但 CMake 没有看到它。有谁知道为什么 cmake 看不到配置文件?
感谢您的时间。

最佳答案

在我看来,您正在定义 OpenBLAS_DIR没有在 find_package 中实际使用它调用(可能需要绝对值 PATHHINT )。

关于c++ - 如何在 CMake 中将 OpenBLAS 定义为子目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67651045/

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