You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows 10 x64环境下xtensor-blas库编译依赖问题求助

Hey there, let's work through this step by step to get xtensor-blas up and running smoothly on your setup!


First, Fix the openblas.dll Not Found Error

The issue here is Windows-specific: when your program runs, it needs to locate the OpenBLAS DLL file. Your CMake configuration links the library correctly at compile time, but the runtime can't find the DLL unless it's in the system PATH or in the same folder as your executable.

Quick Fix (Temporary)

Add the OpenBLAS bin directory to your system PATH:

  • Go to Control Panel > System > Advanced System Settings > Environment Variables
  • Under System Variables, edit PATH and add c:/Users/pruglo/anaconda3/envs/evn/Library/bin
  • Restart CLion for the changes to take effect

Better Fix (Permanent via CMake)

Add a post-build step to your CMakeLists.txt that automatically copies the DLL to your executable's output directory. This way you don't have to modify the system PATH:

add_custom_command(TARGET tstxtensor3 POST_BUILD
                   COMMAND ${CMAKE_COMMAND} -E copy_if_different
                           ${OpenBLAS_LIBRARY}
                           $<TARGET_FILE_DIR:tstxtensor3>)

Optimize Your CMake Configuration

Your current CMake has some redundant and non-standard code. Here's a cleaned-up, modern version that follows best practices:

cmake_minimum_required(VERSION 3.19)
project(tstxtensor3)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON) # Ensures the compiler uses C++20

# Locate OpenBLAS using your Anaconda environment's config
set(OpenBLAS_DIR c:/Users/pruglo/anaconda3/envs/evn/Library/share/cmake/OpenBLAS/)
find_package(OpenBLAS REQUIRED)

# Add your executable
add_executable(tstxtensor3 main.cpp)

# Include directories for xtl/xtensor/xtensor-blas (your copied headers)
target_include_directories(tstxtensor3 PRIVATE .)

# Enable CBLAS support for xtensor-blas
target_compile_definitions(tstxtensor3 PRIVATE HAVE_CBLAS=1)

# Link OpenBLAS properly using the imported target from find_package
target_link_libraries(tstxtensor3 PRIVATE OpenBLAS::OpenBLAS)

# Auto-copy OpenBLAS DLL to output directory
add_custom_command(TARGET tstxtensor3 POST_BUILD
                   COMMAND ${CMAKE_COMMAND} -E copy_if_different
                           ${OpenBLAS_LIBRARY}
                           $<TARGET_FILE_DIR:tstxtensor3>)

Do You Need LAPACK or Other Dependencies?

Great question! xtensor-blas requires BLAS for basic linear algebra operations, and some advanced features (like matrix decompositions, linear solvers) rely on LAPACK.

Luckily, the OpenBLAS package from Conda-Forge already includes LAPACK implementations—you don't need to install it separately. Your current setup should support all xtensor-blas features out of the box.


Building a Portable Project (Avoid Manual Dependency Installs)

To avoid setting up dependencies on every dev machine, here are two solid options:

Option 1: Use CMake FetchContent

Let CMAke automatically download and configure xtl, xtensor, and xtensor-blas for you. Replace your manual header copying with this in your CMakeLists.txt:

include(FetchContent)

# Fetch xtl (dependency for xtensor)
FetchContent_Declare(
    xtl
    GIT_REPOSITORY https://github.com/xtensor-stack/xtl.git
    GIT_TAG 0.7.5 # Use the latest stable version
)

# Fetch xtensor
FetchContent_Declare(
    xtensor
    GIT_REPOSITORY https://github.com/xtensor-stack/xtensor.git
    GIT_TAG 0.25.0
)

# Fetch xtensor-blas
FetchContent_Declare(
    xtensor-blas
    GIT_REPOSITORY https://github.com/xtensor-stack/xtensor-blas.git
    GIT_TAG 0.20.0
)

# Make all dependencies available
FetchContent_MakeAvailable(xtl xtensor xtensor-blas)

Then remove the target_include_directories line for your copied headers—FetchContent handles this automatically.

Option 2: Use vcpkg Package Manager

vcpkg simplifies cross-platform dependency management:

  1. Install vcpkg from its GitHub repo
  2. Run vcpkg install xtensor-blas:x64-windows to install all required dependencies (including OpenBLAS)
  3. In CLion, go to File > Settings > Build, Execution, Deployment > CMake and set the toolchain file to [vcpkg root]/scripts/buildsystems/vcpkg.cmake
  4. Your CMakeLists.txt can then be simplified to just:
    cmake_minimum_required(VERSION 3.19)
    project(tstxtensor3)
    
    set(CMAKE_CXX_STANDARD 20)
    find_package(xtensor-blas REQUIRED)
    
    add_executable(tstxtensor3 main.cpp)
    target_link_libraries(tstxtensor3 PRIVATE xtensor-blas)
    

vcpkg handles all DLL copying and path setup for you, making the project fully portable across dev machines with vcpkg installed.


内容的提问来源于stack exchange,提问作者Michael Pruglo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 11:44:10