1

I am extending C++ library with functionality that requires GRPC. GRPC dependencies are added through VCPKG (example from CMakeLists.txt):

find_package(gRPC CONFIG REQUIRED)

target_link_libraries(
  mylib PRIVATE
  gRPC::grpc++)

Now, that same library has python bindings (where I enter into, for me, an uncharted territory). The library is built through setuptools. The setup itself initially went ok but when I try to load the library I get:

❯ python3
Python 3.8.10 (default, Nov 14 2022, 12:59:47)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mylib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: /usr/local/lib/python3.8/dist-packages/mylib-0.0.0-py3.8-linux-x86_64.egg/mylib.cpython-38-x86_64-linux-gnu.so: undefined symbol: _ZTIN6google8protobuf2io20ZeroCopyOutputStreamE

Missing _ZTIN6google8protobuf2io20ZeroCopyOutputStreamE clearly comes from GRPC dependency. I tried playing with setup.py and including grpc lib folder:

toolchain_args += ['-I/home/atomic/vcpkg/installed/x64-linux/lib']

I also tried extending required libraries list:

libraries += ['libgrpc++', 'libprotobuf']

Grpc is installed under /usr/local/lib/ and also as vcpkg package.

But without any luck. Including libs failed with following error:

/usr/bin/ld: cannot find -llibgrpc++
/usr/bin/ld: cannot find -llibprotobuf
Klark
  • 8,162
  • 3
  • 37
  • 61
  • 1
    Does your target link libraries not look like: `target_link_libraries(mylib PRIVATE gRPC::grpc++)` – Tom McLean Jan 15 '23 at 12:13
  • 1
    It does. Thanks for noticing. Will update the question. – Klark Jan 15 '23 at 12:16
  • Ive done the exact same thing recently (grpc client with python bindings with pybind), so hopefully I can help. Before I share my entire process, doing `set_target_properties(mylib PROPERTIES POSITION_INDEPENDENT_CODE TRUE)` helped with a lot of my issues, as the code *can* get built in a tmp folder then moved after. Does this fix your problem? – Tom McLean Jan 15 '23 at 12:23
  • Just tried it out. Still no luck. Would be great if you could share additional pointers. – Klark Jan 15 '23 at 17:02
  • Can you share your pybind11 code? Are you trying to make an instance of a C++ grpc class that doesnt have python bindings? I can try write up an example github repo, as it will be useful for future reference for me as well. – Tom McLean Jan 15 '23 at 17:05
  • grpc classes are internal to mylib and aren't exposed through pybind at all. – Klark Jan 15 '23 at 17:39

0 Answers0