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

Python bindings #24

Open
thedrow opened this issue Jan 24, 2018 · 5 comments
Open

Python bindings #24

thedrow opened this issue Jan 24, 2018 · 5 comments

Comments

@thedrow
Copy link

thedrow commented Jan 24, 2018

Is there a Python binding to this library?
If not, can we add one?

@graetzer
Copy link
Contributor

Not yet, feel free to submit a pull request for it

@kfreezen
Copy link

kfreezen commented Oct 5, 2023

I've been tinkering with Python bindings for this library. I'm getting an ImportError due to a missing symbol. This missing symbol also seems to be missing from libvelocypack.a

Here's the ImportError I'm getting:

ImportError: dlopen(/Users/.../Library/Caches/pypoetry/virtualenvs/velocypack-IZ9-pmhB-py3.11/lib/python3.11/site-packages/vpack.cpython-311-darwin.so, 0x0002): symbol not found in flat namespace (__ZNK8arangodb10velocypack9SliceBaseINS0_5SliceES2_E15byteSizeDynamicEPKh)

If I run

nm -g build/libvelocypack.a | grep __ZNK8arangodb10velocypack9SliceBaseINS0_5SliceES2_E15byteSizeDynamicEPKh

I get nothing. Is there something obvious that I'm missing?

If it's useful to you, I can fork and open a PR with what I've got so far.

@jsteemann
Copy link
Contributor

Unfortunately I don't know much about Python bindings and how to create them.
So I can't really tell where this ImportError comes from.

I tried creating a small test program and linking it to libvelocypack.a, in order to see if there are any errors related to missing symbols or linking.
I have used the current state of the main branch. Here's my test program (test.cpp):

#include <velocypack/Slice.h>
#include <velocypack/Builder.h>

#include <iostream>

int main() {
  using namespace arangodb::velocypack;

  Builder b;
  b.openObject();
  b.add("foo", Value("bar"));
  b.close();

  std::cout << b.slice().toJson() << ", " << b.slice().byteSize() << "\n";
}

I compiled & linked it with g++ (g++-11.4) via

g++ -std=c++20 -Wall -Iinclude -Lbuild test.cpp -lvelocypack

and executed it with ./a.out.
All the steps worked fine for me.
I also tried building and linking with clang++-14 and it also worked fine.

So at least for me the generated libvelocypack.a seems to be usable from external programs.

As mentioned before, I am not really aware of how Python bindings work, but do they actually supported using static libraries? Just wondering (random guess) if they may require using a dynamic library instead.

@kfreezen
Copy link

My understanding is limited as well, but the bindings file produced in this case is a .so file. There is an extremely simple case that did work without bringing me this ImportError, but once I started expanding my Cython code, I hit this error. Maybe that's the clue to how I should continue. 🤔

@kfreezen
Copy link

Spent some time hacking around on it this morning and discovered that I have to define everything just so-so in Cython, or we are going to have a bad time. So much for remaining ignorant of advanced C++ templating in Cython.

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

4 participants