libcutter icon indicating copy to clipboard operation
libcutter copied to clipboard

cannot import python cutter package

Open bubbapizza opened this issue 3 years ago • 4 comments

I think I managed to build the "cutter" package for python but when I try to import it, I get this message:

ImportError: ./_pycutter.so: undefined symbol: _ZN6Device1CC1ENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE

bubbapizza avatar Feb 14 '22 16:02 bubbapizza

I've reproduced this on Debian 10.

Demangles to Device::C::C(std::__cxx11::basic_string<char, std::char_traits, std::allocator >), which is the device-C constructor.

I can see that lib/CMakeFiles/cutter.dir/device_c.cpp.o implements the text-section symbol for _ZN6Device1CC1ENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE, but that it's marked as undefined in _pycutter.so, this makes me think _pycutter.so is not being built correctly, and somehow not including the symbols from device_c.cpp

patching lib/CMakeFiles.txt like so gets further:

  • swig_add_library(pycutter TYPE SHARED LANGUAGE python SOURCES cutter.i)
  • swig_add_library(pycutter TYPE SHARED LANGUAGE python SOURCES cutter.i ${cutter_files})

but then fails with: ImportError: dynamic module does not define init function (init_pycutter)

Perhaps older version of swig implemented that for us, or perhaps it wasn't required?

rsaxvc avatar Feb 15 '22 02:02 rsaxvc

it's something to do with the dynamic libraries not working or something. I was messing around with it a couple days ago trying to figure out how the hell swig works. Does anybody here know how CMake and Swig works? It seems only vangdfang has any idea how it works.

It looks like you have to somehow statically link together device_c.cpp.o, serial_port.cpp.o, device.cpp.o and btea.c.o in lib/CmakeFiles/cutter.dir with lib/CmakeFiles/pycutter.dir/CMakeFiles/pycutter.dir/cutterPYTHON_wrap.cxx.o.

I think I did it a couple days ago but I don't have a log of what I did. IIRC got it linked but it wouldn't import into python. I was going off this article here: https://stackoverflow.com/questions/5302933/g-linking-and-swig

bubbapizza avatar Feb 17 '22 05:02 bubbapizza

Ohhh wait, I think I had the same error about the init function, that's what bombed out. I was thinking it was a python2 - python3 thing. Maybe swig doesn't work with python3? I was using python3.8 btw

bubbapizza avatar Feb 17 '22 05:02 bubbapizza

It looks like swig is supposed to generate compatible python for both python 2 and 3. https://github.com/swig/swig/issues/695

This largely seems like a cmake issue passing in the right objects in the right order to build the dynamic lib. When I updated to support newer cmakes it looks like a broke this and didn't notice because the build still completed.

rsaxvc avatar Feb 18 '22 19:02 rsaxvc