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

binder does not generate bindings #150

Open
Thermi opened this issue Feb 4, 2021 · 2 comments
Open

binder does not generate bindings #150

Thermi opened this issue Feb 4, 2021 · 2 comments

Comments

@Thermi
Copy link

Thermi commented Feb 4, 2021

Hi, I'm trying to use binder to generate python bindings for libmdbx by pointing it at its mdbx.h++ file. That doesn't work though. binder does not generate any bindings, except the python module declaration. When the cpp file is built and loaded as a Python module, only the mdbx module is available, but none of functions, classes, or enums declared in mdbx.h++.

binder is in ~/prefix/bin/ and my cmdline is the following (when CWD is ~/prefix):
bin/binder -p build --annotate-includes --root-module mdbx --bind mdbx --prefix generated all_includes.hpp -- -DNDEBUG -I /usr/lib/clang/11.0.1/include/ -I/usrinclude --std=c++20

This is with the newest binder version from this repo. clang and llvm version is 11.0.1.
It generates the following mdbx.cpp file (mdbx.sources contains "mdbx.cpp" and mdbx.modules is empty):

#include <map>
#include <memory>
#include <stdexcept>
#include <functional>
#include <string>

#include <pybind11/pybind11.h>

typedef std::function< pybind11::module & (std::string const &) > ModuleGetter;



PYBIND11_MODULE(mdbx, root_module) {
        root_module.doc() = "mdbx module";

        std::map <std::string, pybind11::module> modules;
        ModuleGetter M = [&](std::string const &namespace_) -> pybind11::module & {
                auto it = modules.find(namespace_);
                if( it == modules.end() ) throw std::runtime_error("Attempt to access pybind11::module for namespace " + namespace_ + " before it was created!!!");
                return it->second;
        };

        modules[""] = root_module;

        std::vector< std::pair<std::string, std::string> > sub_modules {
        };
        for(auto &p : sub_modules ) modules[p.first.size() ? p.first+"::"+p.second : p.second] = modules[p.first].def_submodule(p.second.c_str(), ("Bindings for " + p.first + "::" + p.second + " namespace").c_str() );

        //pybind11::class_<std::shared_ptr<void>>(M(""), "_encapsulated_data_");


}
@lyskov
Copy link
Member

lyskov commented Feb 15, 2021

@Thermi looks like Binder was not able to find any object/namespaces to bind. Could you please try to replace --bind mdbx with --bind "" and see if that make any difference? Thanks,

@lyskov
Copy link
Member

lyskov commented Feb 15, 2021

Also, i briefly looked at mdbx.h++ and looks like there is a lot of low level c-style functions, some of which might not be possible to bind. If above suggestion does not yield more generated code: could you please add something like struct Dummy {int a;}; inside mdbx.h++ and see if that makes any difference? (ie rare chance that none of other objects in mdbx.h++ could be bound)

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

2 participants