xtensor-stack / xtensor-python

Python bindings for xtensor
BSD 3-Clause "New" or "Revised" License
345 stars 58 forks source link

Cannot compile python bindings #247

Open sbuschjaeger opened 3 years ago

sbuschjaeger commented 3 years ago

I have some issues compiling python bindings for my project involving xtensor. My CMakeList.txt looks like this

cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
project(XTensorPythonTest LANGUAGES CXX)

set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})

SET(CMAKE_CXX_STANDARD 17)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)

if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE Release)
endif()

set(CMAKE_CXX_FLAGS "-Wall -Wextra -g")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -ffast-math -march=native -mtune=native")

find_package(xtl REQUIRED)
find_package(xtensor REQUIRED)

find_package(xtensor-python REQUIRED)
find_package(pybind11 REQUIRED)
find_package(NumPy REQUIRED)

message(STATUS "Found numpy: ${NUMPY_INCLUDE_DIRS}")

# These are my includes
include_directories("./include")

# xtensor-python requires numpy includes
include_directories(${NUMPY_INCLUDE_DIRS})

add_executable(run_tests ${SOURCES} run_tests.cpp)

target_link_libraries(run_tests xtensor xtensor::optimize xtensor::use_xsimd xtensor-python)
pybind11_add_module(XTensorPythonTest include/Python.cpp)

with Python.cpp

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
// #include <pybind11/stl_bind.h>
#include <pybind11/operators.h>
#include <pybind11/functional.h>

#define FORCE_IMPORT_ARRAY
#include "xtensor-python/pyarray.hpp"     // Numpy bindings

// My includes

namespace py = pybind11;

PYBIND11_MODULE(XTensorPythonTest, m) {
/* PyBind Stuff */
}

My conda environment has installed:

I use gcc 10.2 (system installation) and cmake 3.19.1 (system installation). I also have copied FindNumPy.cmake into cmake/ (Which would have been helpful if documentation would mention this)

Now during compilation I get

include/pybind11/cast.h:921:43: error: ‘std::remove_reference<pybind11::detail::type_caster<xt::xarray_container<xt::uvector<double, std::allocator<double> >, xt::layout_type::row_major, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag>, void>&>::type’ {aka ‘class pybind11::detail::type_caster<xt::xarray_container<xt::uvector<double, std::allocator<double> >, xt::layout_type::row_major, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag>, void>’} has no member named ‘operator pybind11::detail::xtensor_type_caster_base<xt::xarray_container<xt::uvector<double, std::allocator<double> >, xt::layout_type::row_major, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag> >::cast_op_type<const xt::xarray_container<xt::uvector<double, std::allocator<double> >, xt::layout_type::row_major, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag>&>’
  920 |     return std::move(caster).operator
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~      
  921 |         typename make_caster<T>::template cast_op_type<typename std::add_rvalue_reference<T>::type>();

...

cast.h:921:43: error: ‘std::remove_reference<pybind11::detail::type_caster<xt::xarray_container<xt::uvector<unsigned int, std::allocator<unsigned int> >, xt::layout_type::row_major, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag>, void>&>::type’ {aka ‘class pybind11::detail::type_caster<xt::xarray_container<xt::uvector<unsigned int, std::allocator<unsigned int> >, xt::layout_type::row_major, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag>, void>’} has no member named ‘operator pybind11::detail::xtensor_type_caster_base<xt::xarray_container<xt::uvector<unsigned int, std::allocator<unsigned int> >, xt::layout_type::row_major, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag> >::cast_op_type<const xt::xarray_container<xt::uvector<unsigned int, std::allocator<unsigned int> >, xt::layout_type::row_major, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag>&>’
make[2]: *** [CMakeFiles/PyBPE.dir/build.make:82: CMakeFiles/PyBPE.dir/include/Python.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:97: CMakeFiles/PyBPE.dir/all] Error 2