无法在Windows上使用xtensor-blas [英] Cannot use xtensor-blas on Windows

查看:79
本文介绍了无法在Windows上使用xtensor-blas的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

免责声明::我是build/make/packages/cmake的菜鸟.
我的目标:在C ++中使用 xtensor-blas
我的环境:Win10 x64,CLion2021
我的问题:无法获得最简单的示例进行编译.关于项目依赖项.
我尝试过:
1)使用我可以在Google上找到的每个教程手动下载和编译openBLAST-总是在遇到其他问题时停止.我没有"nmake"消息或由于某种原因构建失败,或者我收到未定义的引用"等等-我已经不知所措了几天.分步演练将不胜感激.
2)我最接近的是使用anaconda conda install -c conda-forge openblas ,然后复制粘贴"include";从 xtl xtensor xtensor-blas 到我的项目的目录.我的CMakeLists.txt:

Disclaimer: I'm a noob at building/make/packages/cmake.
My goal: Use xtensor-blas library in C++
My env: Win10 x64, CLion2021
My problem: Can't get the simplest examples to compile. Sth about project dependencies.
I tried:
1) downloading and compiling openBLAST manually using every tutorial I could google - always stopped at different problems. Either I don't have "nmake" or build failed for some reason, or I get "undefined reference" etc. - I've been overwhelmed for a couple of days. A step-by-step walkthrough would be appreciated.
2) the closest I got was using anaconda conda install -c conda-forge openblas, then copy-pasting "include" directories from xtl,xtensor,xtensor-blas to my project. My CMakeLists.txt:

cmake_minimum_required(VERSION 3.19)
project(tstxtensor3)

set(CMAKE_CXX_STANDARD 20)

add_executable(tstxtensor3 main.cpp)

include_directories(.)

add_definitions(-DHAVE_CBLAS=1)

set(OpenBLAS_DIR c:/Users/pruglo/anaconda3/envs/evn/Library/share/cmake/OpenBLAS/)
find_package(OpenBLAS REQUIRED)

if (OpenBLAS_FOUND)
    include_directories(${OpenBLAS_INCLUDE_DIRS})
    target_link_libraries(tstxtensor3 c:/Users/pruglo/anaconda3/envs/evn/Library/lib/openblas.lib ${OpenBLAS_LIBRARY})
else ()
    message("OpenBLAS NOT FOUND!")
endif ()

Cmake成功加载,并且 OpenBLAS_FOUND true .但是,当我编译cpp时,在加载共享库时出现错误:openblas.dll:无法打开共享对象文件:没有这样的文件或目录进程结束,退出代码为127
注意: OpenBLAS_INCLUDE_DIRS 扩展为 c:/Users/pruglo/anaconda3/envs/evn/Library/include/openblas ,而 OpenBLAS_LIBRARY 扩展为> c:/Users/pruglo/anaconda3/envs/evn/Library/bin/openblas.dll

Cmake loads successfuly, and OpenBLAS_FOUND is true. But when I compile my cpp, I get error while loading shared libraries: openblas.dll: cannot open shared object file: No such file or directory Process finished with exit code 127
Note: OpenBLAS_INCLUDE_DIRS expands to c:/Users/pruglo/anaconda3/envs/evn/Library/include/openblas and OpenBLAS_LIBRARY expands to c:/Users/pruglo/anaconda3/envs/evn/Library/bin/openblas.dll

其他问题:

  • 我是否需要LAPACK或其他用于 xtensor-blas 的东西?
  • 我可以移植构建我的项目,以便不需要为开发的每台PC安装所有软件吗?

推荐答案

免责声明:我离Windows专家还很远(我只是在持续集成中使用它来进行测试).

Disclaimer: I'm far from a Windows expert (I just use it in Continuous Integration for testing).

您应该能够使用 xtensor-blas 提供的目标.因此,应该可行(在任何平台上):

You should be able to use the target provided by xtensor-blas. So what should be possible is to do (on any platform):

cmake_minimum_required(VERSION 3.1)

set(CMAKE_BUILD_TYPE Release)

project(myexec)
find_package(xtensor)
find_package(xtensor-blas)
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} xtensor xtensor-blas)

自从您谈论 conda 以来,这确实是我发现最简单的方法,并且可以在所有平台上使用.我真的只需要做其他事情

Since you talk about conda, that is indeed what I find easiest and works on all platforms. I really had to do not much else than

conda install -c conda-forge cmake xtensor xtensor-blas

(在我加载的环境中).

(in my loaded environment).

这里可能有一个陷阱:请注意,我使用了 conda 中的 CMake .可能是因为它配置了 conda 的正确路径(但我不太确定是诚实的).

There could be a pitfall here: Notice that I used CMake from conda. It might be that is it configured with the right paths for conda (but I'm not really sure to be honest).

为完整性起见,我认为您可以使用(从源目录中加载了 conda 环境):

For completeness, I think that you can use (from your source directory, with your conda environment loaded):

conda install -c conda-forge ninja
cmake -G "NMake Makefiles" -Bbuild
cd build
nmake

要独立运行,我用文档中的示例进行了测试:

To be stand-alone, I tested with an example from the docs:

#include <xtensor.hpp>
#include <xtensor-blas/xlinalg.hpp>

int main()
{
    xt::xarray<double> a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
    auto d = xt::linalg::det(a);
    std::cout << d << std::endl;  // 6.661338e-16
    return 0;
}

这篇关于无法在Windows上使用xtensor-blas的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆