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 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
Extra questions:
xtensor-blas
?Disclaimer: I'm far from a Windows expert (I just use it in Continuous Integration for testing).
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)
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).
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).
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;
}