0

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:

  • do I need LAPACK or other stuff for xtensor-blas?
  • can I build my project portably so that I don't need to install everything for every pc I develop on?
Ðаn
  • 10,934
  • 11
  • 59
  • 95
  • Maybe the dll is not where it is looking. Maybe it was compiled for a different compiler msvc instead of mingw (which I expect you are using). Maybe you are mixing 32 and 64 bit. – drescherjm Mar 30 '21 at 15:46
  • ***Either I don't have "nmake"*** That comes with msvc – drescherjm Mar 30 '21 at 15:48
  • I would try either msvc (possibly using vcpkg) or mingw using msys2 – drescherjm Mar 30 '21 at 16:06
  • Not a great Windows expert myself. But what is to look how the library is tested : https://github.com/xtensor-stack/xtensor-blas/blob/master/.appveyor.yml , https://github.com/xtensor-stack/xtensor-blas/blob/master/CMakeLists.txt , https://github.com/xtensor-stack/xtensor-blas/blob/master/xtensor-blasConfig.cmake.in – Tom de Geus Mar 31 '21 at 08:14
  • @TomdeGeus I don't understand those files. Can I run them somehow? – Michael Pruglo Mar 31 '21 at 09:35
  • 1
    @MichaelPruglo Those files you cannot run. They were meant for you as reference to see how things are configured on a the continuous integration, for you to see if you might have a crucial difference in configuration. The CMake files are there just to give you a reference to see how things are done internally, as it may help you to debug quicker – Tom de Geus Mar 31 '21 at 16:42

1 Answers1

1

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;
}
Tom de Geus
  • 5,625
  • 2
  • 33
  • 77
  • didn't work for me - tried re-installing conda and running your command, tried your cmakelists.txt - got errors from "find_package" - added `set(xtensor_DIR ...)` for `xtl` `xtensor` and `xtensor-blas`, now I get "Could not find BLAS (missing: BLAS_LIBRARIES)" when executing `find_package(xtensor-blas)`
    1) what do you mean by "loaded environment"?
    2) what do you mean by "source directory"? Where my project is?
    thanks for your time anyway
    – Michael Pruglo Mar 31 '21 at 09:18
  • @MichaelPruglo the fact that you had to set paths is not how things are supposed to be and probably the reason why you cannot find *blas*. Basically CMake is there for you to link libraries without having to deal with paths. That makes is powerful, you provided a set of dependencies, and CMake will take care of paths on different platforms and different systems. So there is probably a crucial settings missing on your system impeding CMake to do its job. Are you sure that you are running the CMake from *conda*? – Tom de Geus Mar 31 '21 at 16:40
  • thanks for being here! Frankly, I'm losing hope. Good call about cmake - I was indeed using an IDE bundled version. Chaning to conda's cmake didn't help, though - i'm getting `Could NOT find BLAS (missing: BLAS_LIBRARIES)`. I found a phrase `To build the tests or actually use xtensor-blas, you will need binaries for openblas lapack which are also available on conda-forge.` Ran a `conda install` - still same result. Also followed that `.appveyor.yml` file - it involved modifying files and installing additional library - still no luck. Any guidance would be appreciated. – Michael Pruglo Apr 01 '21 at 14:55
  • @MichaelPruglo It seems that you may have gotten an step closer. To check, an intermediate step to take, is to see if your CMake can find any library that you install using conda. Maybe you can try something that does not require linking first. For example you could try just `xtensor` first. Then, if that works, you should check that blas was indeed installed in you conda environment using `conda list` is the loaded environment (this should be the case as they are dependencies of `xtensor-blas`) – Tom de Geus Apr 01 '21 at 15:53
  • intermediate step successful - I *am* able to `find_package(xtensor) target_link_libraries(... xtensor)`. Second step also successful - `conda list` gives me `... blas 1.0 ... cmake 3.19.7 ... conda 4.10.0 ... libblas 3.8.0 ... libcblas 3.8.0 ... liblapack 3.8.0 ... m2w64-openblas 0.2.19 ... openblas 0.3.12 ...` – Michael Pruglo Apr 01 '21 at 16:23
  • I made a lot of changes to IDE and Windows environment variables, so I'm not sure what worked. Anyways, the crucial point was to restart my computer (?) I just came in the next day and it linked. However, my celebrations weren't long - because it works INCORRECT. The standard examples compile to give 0 and -inf. That's an unexpected turn of events. – Michael Pruglo Apr 02 '21 at 12:25
  • @MichaelPruglo great that it worked! Sorry to hear that you are not done debugging. I guess that it should be discussed in a separate question if debugging does not resolve the issue – Tom de Geus Apr 03 '21 at 06:25