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

Can't bind function with double pointer parameter #417

Closed
dangirsh opened this issue Sep 19, 2016 · 7 comments
Closed

Can't bind function with double pointer parameter #417

dangirsh opened this issue Sep 19, 2016 · 7 comments

Comments

@dangirsh
Copy link

dangirsh commented Sep 19, 2016

I can successfully compile and run the example here for wrapping the function int add(int i, int j). If I change the type of j to char **, I get this compiler error:

./include/pybind11/cast.h: In instantiation of ‘ReturnValue pybind11::detail::type_caster<std::tuple<_Elements ...> >::call(Func&&, pybind11::detail::index_sequence<Index ...>) [with ReturnValue = int; Func = int (*&)(int, char**); long unsigned int ...Index = {0ul, 1ul}; Tuple = {int, char**}]’:
./include/pybind11/cast.h:694:20:   required from ‘typename std::enable_if<(! std::is_void<_Res>::value), ReturnValue>::type pybind11::detail::type_caster<std::tuple<_Elements ...> >::call(Func&&) [with ReturnValue = int; Func = int (*&)(int, char**); Tuple = {int, char**}; typename std::enable_if<(! std::is_void<_Res>::value), ReturnValue>::type = int]’
./include/pybind11/pybind11.h:133:63:   required from ‘pybind11::cpp_function::initialize(Func&&, Return (*)(Args ...), const Extra& ...) [with Func = int (*&)(int, char**); Return = int; Args = {int, char**}; Extra = {pybind11::name, pybind11::sibling, pybind11::scope, char [34], pybind11::arg, pybind11::arg}]::__lambda7’
./include/pybind11/pybind11.h:117:22:   required from ‘struct pybind11::cpp_function::initialize(Func&&, Return (*)(Args ...), const Extra& ...) [with Func = int (*&)(int, char**); Return = int; Args = {int, char**}; Extra = {pybind11::name, pybind11::sibling, pybind11::scope, char [34], pybind11::arg, pybind11::arg}]::__lambda7’
./include/pybind11/pybind11.h:117:19:   required from ‘void pybind11::cpp_function::initialize(Func&&, Return (*)(Args ...), const Extra& ...) [with Func = int (*&)(int, char**); Return = int; Args = {int, char**}; Extra = {pybind11::name, pybind11::sibling, pybind11::scope, char [34], pybind11::arg, pybind11::arg}]’
./include/pybind11/pybind11.h:46:9:   required from ‘pybind11::cpp_function::cpp_function(Return (*)(Args ...), const Extra& ...) [with Return = int; Args = {int, char**}; Extra = {pybind11::name, pybind11::sibling, pybind11::scope, char [34], pybind11::arg, pybind11::arg}]’
./include/pybind11/pybind11.h:545:80:   required from ‘pybind11::module& pybind11::module::def(const char*, Func&&, const Extra& ...) [with Func = int (*)(int, char**); Extra = {char [34], pybind11::arg, pybind11::arg}]’
example.cpp:13:87:   required from here
./include/pybind11/cast.h:711:85: error: cannot convert ‘char*’ to ‘char**’ in argument passing
             .operator typename make_caster<Tuple>::template cast_op_type<Tuple>()...);
                                                                                     ^
./include/pybind11/cast.h: In member function ‘ReturnValue pybind11::detail::type_caster<std::tuple<_Elements ...> >::call(Func&&, pybind11::detail::index_sequence<Index ...>) [with ReturnValue = int; Func = int (*&)(int, char**); long unsigned int ...Index = {0ul, 1ul}; Tuple = {int, char**}]’:
./include/pybind11/cast.h:712:5: warning: control reaches end of non-void function [-Wreturn-type]
     }
./include/pybind11/cast.h: In instantiation of ‘ReturnValue pybind11::detail::type_caster<std::tuple<_Elements ...> >::call(Func&&, pybind11::detail::index_sequence<Index ...>) [with ReturnValue = int; Func = int (*&)(int, char**); long unsigned int ...Index = {0ul, 1ul}; Tuple = {int, char**}]’:
./include/pybind11/cast.h:694:20:   required from ‘typename std::enable_if<(! std::is_void<_Res>::value), ReturnValue>::type pybind11::detail::type_caster<std::tuple<_Elements ...> >::call(Func&&) [with ReturnValue = int; Func = int (*&)(int, char**); Tuple = {int, char**}; typename std::enable_if<(! std::is_void<_Res>::value), ReturnValue>::type = int]’
./include/pybind11/pybind11.h:133:63:   required from ‘pybind11::cpp_function::initialize(Func&&, Return (*)(Args ...), const Extra& ...) [with Func = int (*&)(int, char**); Return = int; Args = {int, char**}; Extra = {pybind11::name, pybind11::sibling, pybind11::scope, char [34], pybind11::arg, pybind11::arg}]::__lambda7’
./include/pybind11/pybind11.h:117:22:   required from ‘struct pybind11::cpp_function::initialize(Func&&, Return (*)(Args ...), const Extra& ...) [with Func = int (*&)(int, char**); Return = int; Args = {int, char**}; Extra = {pybind11::name, pybind11::sibling, pybind11::scope, char [34], pybind11::arg, pybind11::arg}]::__lambda7’
./include/pybind11/pybind11.h:117:19:   required from ‘void pybind11::cpp_function::initialize(Func&&, Return (*)(Args ...), const Extra& ...) [with Func = int (*&)(int, char**); Return = int; Args = {int, char**}; Extra = {pybind11::name, pybind11::sibling, pybind11::scope, char [34], pybind11::arg, pybind11::arg}]’
./include/pybind11/pybind11.h:46:9:   required from ‘pybind11::cpp_function::cpp_function(Return (*)(Args ...), const Extra& ...) [with Return = int; Args = {int, char**}; Extra = {pybind11::name, pybind11::sibling, pybind11::scope, char [34], pybind11::arg, pybind11::arg}]’
./include/pybind11/pybind11.h:545:80:   required from ‘pybind11::module& pybind11::module::def(const char*, Func&&, const Extra& ...) [with Func = int (*)(int, char**); Extra = {char [34], pybind11::arg, pybind11::arg}]’
example.cpp:13:87:   required from here
./include/pybind11/cast.h:711:85: error: cannot convert ‘char*’ to ‘char**’ in argument passing
             .operator typename make_caster<Tuple>::template cast_op_type<Tuple>()...);
                                                                                     ^
./include/pybind11/cast.h: In member function ‘ReturnValue pybind11::detail::type_caster<std::tuple<_Elements ...> >::call(Func&&, pybind11::detail::index_sequence<Index ...>) [with ReturnValue = int; Func = int (*&)(int, char**); long unsigned int ...Index = {0ul, 1ul}; Tuple = {int, char**}]’:
./include/pybind11/cast.h:712:5: warning: control reaches end of non-void function [-Wreturn-type]
     }

Are double pointers supported? If not, do you have any workarounds for calling the main function of C++ programs (which must have signature int main(int argc, char **argv))?

@wjakob
Copy link
Member

wjakob commented Sep 19, 2016

Double pointer arguments are not supported by pybind11.

@wjakob wjakob closed this as completed Sep 19, 2016
@wjakob
Copy link
Member

wjakob commented Sep 19, 2016

(You could try to bind a lambda function which converts from a std::vectorstd::string or so)

@dangirsh
Copy link
Author

Thanks for the fast reply! It might be worth adding a list of known shortcomings to the main Readme to save everyone time. I'll try you suggestion now :)

@Pulsar18
Copy link

@dangirsh: This is issue is already quite old, but I have the same problem and would like to ask whether you found a solution and if so how that looked like?

@dangirsh
Copy link
Author

Sorry @Pulsar18, too long ago to recall (and I no longer have access to the relevant code).

@levinandrew
Copy link

@Pulsar18 I am having the same issue now, were you able to find a satisfactory solution?

@Foadsf
Copy link

Foadsf commented Feb 3, 2020

I had a similar issue where I had to have int argc and char** argv defined inside a function (they were required by other non-open-source functions). So I ended up changing the function from

int run(int argc, char** argv){
// some stuff
}

to

int run() {

    int argc = 1;
    char* argv[] = {"NameOfTheExecutableModule"};

// same stuff
}

more info here.

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

No branches or pull requests

5 participants