Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing to build python bindings #37

Closed
SomeoneSerge opened this issue Apr 12, 2023 · 12 comments
Closed

Failing to build python bindings #37

SomeoneSerge opened this issue Apr 12, 2023 · 12 comments

Comments

@SomeoneSerge
Copy link

Hi! Built the tests fine, but gcc doesn't seem to like the signatures in the python bindings

error: invalid 'static_cast' from type '<unresolved overloaded function type>' to type 'std::string (*)(const xt::pytensor<double, 1, xt::layout_type::dynamic>&)' {aka 'std::__cxx11::basic_string<char> (*)(const xt::pytensor<dou
       │ ble, 1, xt::layout_type::dynamic>&)'}
  69   │    61 |         static_cast<std::string (*)(const xt::pytensor<double, 1>&)>(&cppcolormap::rgb2hex),

Logs: https://gist.github.com/SomeoneSerge/2507244e5bc3b11982948ff0ed86a681
Getting the same error with gcc11 and gcc12.
Pybind11 version: pybind11-2.10.3/include (found version "2.10.3")
Built with: SomeoneSerge/pkgs@b0274d7

@tdegeus
Copy link
Owner

tdegeus commented Apr 12, 2023

Thanks! I tried debugging here #38 but unfortunately the CI works fine on Linux GCC 11.3.0. This makes it a bit harder to understand what is bugging the compiler and to solve it. It seems that the compiler has a hard time deciding between

template <class T, typename std::enable_if_t<xt::get_rank<T>::value != 1, int> = 0>
std::vector<std::string> rgb2hex(const T& arg);

template <class T, typename std::enable_if_t<xt::get_rank<T>::value == 1, int> = 0>
std::string rgb2hex(const T& arg);

Could you tried by adding the template explicitly to main.cpp:

    m.def(
        "rgb2hex",
        static_cast<std::string (*)(const xt::pytensor<double, 1>&)>(&cppcolormap::rgb2hex<xt::pytensor<double, 1>>),
        DOC("rgb2hex")
    );

    m.def(
        "rgb2hex",
        static_cast<std::vector<std::string> (*)(const xt::pytensor<double, 2>&)>(
            &cppcolormap::rgb2hex<xt::pytensor<double, 2>>
        ),
        DOC("rgb2hex")
    );

?
Thanks!

@SomeoneSerge
Copy link
Author

SomeoneSerge commented Apr 12, 2023

Quick update: still getting the same error at the first overload, i.e. one that returns std::string rather than a vector. The second one compiles. By the way, shouldn't the first one also consume a pytensor? Like pytensor<double, 1> (edit: I see it already does) To be precise, here's the full diff I tried: https://github.com/SomeoneSerge/cppcolormap/pull/1/files

TODO: I should compare xtensor and pybind11 versions, and maybe set up a separate gh action to reproduce the failures more easily

@tdegeus
Copy link
Owner

tdegeus commented Apr 12, 2023

Thanks for the update. That help to narrow it down. If I read better it seems that the compiler converts the std::string to std::__cxx11::basic_string<char> and then is naturally confused. Maybe #41 helps? Otherwise this might be a useful reference https://stackoverflow.com/questions/40705852/undefined-reference-to-std-cxx11basic-string-in-boost-on-travis-ci .

@SomeoneSerge
Copy link
Author

No, that doesn't help yet, and I don't think it's got anything to do with cxx11 abi: the vector of strings seems to be fine.
By the way, I get this warning from ccls:

address of overloaded function 'rgb2hex' cannot be static_cast to type 'std::string (*)(const xt::pytensor<double, 1> &)' (aka 'basic_string<char> (*)(const pytensor<double, 1> &)')

@tdegeus
Copy link
Owner

tdegeus commented Apr 12, 2023

Just to be sure, are you on xtensor-python >=0.25.2 ?

@SomeoneSerge
Copy link
Author

0.25.1

@tdegeus
Copy link
Owner

tdegeus commented Apr 12, 2023

Then problem solved. xt::pytensor only has the static rank property since 0.25.2 (see xtensor-stack/xtensor-python#241 ) . So pre-0.25.2 the compiler throws out

template <class T, typename std::enable_if_t<xt::get_rank<T>::value == 1, int> = 0>

@tdegeus
Copy link
Owner

tdegeus commented Apr 12, 2023

For future reference 2fe9454

@SomeoneSerge
Copy link
Author

SomeoneSerge commented Apr 12, 2023

Perfect, thanks! Maybe also a VERSION in find_package?

EDIT: I'll test with a newer xtensor and close the issue if that works out

@tdegeus
Copy link
Owner

tdegeus commented Apr 12, 2023

Perfect, thanks! Maybe also a VERSION in find_package?

Sounds great, a PR is welcome

@SomeoneSerge
Copy link
Author

SomeoneSerge commented Apr 12, 2023

xtensor-python 0.26.1, works like a charm

Frankly though, maybe 0.25.2 deserved at least a minor version bump, not just the patch version 😆

@tdegeus
Copy link
Owner

tdegeus commented Apr 12, 2023

xtensor*'s versioning is a mystery to me ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants