2

OS: Ubuntu 16.04 64-bit

Python: 2.7.12

I have a really simple Python program which is just loading two libraries libhidapi-hidraw and libpcProxAPI. The latter is dependent on the former.

from ctypes import *

hidapi = CDLL('/home/wsharp/Source/pyprox/libhidapi-hidraw.so')
pcProxAPI = CDLL('/home/wsharp/Source/pyprox/libpcProxAPI.so')

r = pcProxAPI.usbConnect()

If I run >python myfile.py I receive the following error: "undefined symbol: hid_send_feature_report"

However if I run >LD_PRELOAD=./libhidapi-hidraw.so python myfile.py I don't receive any issues.

I've tried placing the libhidapi-hidraw.so in /usr/lib and other paths sourced by ldconfig with no luck. I'm not sure what I'm doing wrong, but it's driving me nuts. Any help would be appreciated.

EDIT

Including the output of sudo ldconfig -v 2>/dev/null | grep -v ^$'\t'

sudo ldconfig -v 2>/dev/null | grep -v ^$'\t'
/usr/lib/x86_64-linux-gnu/libfakeroot:
/lib/i386-linux-gnu:
/usr/lib/i386-linux-gnu:
/usr/local/lib:
/lib/x86_64-linux-gnu:
/usr/lib/x86_64-linux-gnu:
/usr/lib/x86_64-linux-gnu/mesa-egl:
/usr/lib/x86_64-linux-gnu/mesa:
/lib:
/usr/lib:

EDIT 2

ldd libpcProxAPI.so
    linux-vdso.so.1 =>  (0x00007fff9d3b9000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f276c231000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f276bf28000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f276bd11000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f276b948000)
    /lib64/ld-linux-x86-64.so.2 (0x000055dfcf780000)
fortune
  • 1,527
  • 2
  • 15
  • 22

1 Answers1

1

Confirm if you are placing the file in one of the paths searched by linker:

ldconfig -v 2>/dev/null | grep -v ^$'\t'

If it is not, you have few options:

  1. Set LD_LIBRARY_PATH to the directory containing the .so files
  2. Add the directory to /etc/ld.so.conf and run ldconfig - (need root)
codegrep_admin
  • 519
  • 4
  • 7
  • Output of that command in the original post. I've placed the *.so file in `/usr/lib` and `/usr/lib/x86_64-linux-gnu`. Still no luck. – fortune Nov 20 '16 at 20:39
  • If you run ldd on libProxy.., does it show the dependency correctly? If not did you compile it? You have to link the dependencies for it to automatically pick up – codegrep_admin Nov 20 '16 at 21:36
  • 1
    If you cant recompile, ldpreload is indeed a workaround – codegrep_admin Nov 20 '16 at 21:40
  • I ran `ldd` on the library; output in the original post. I don't see `hidapi-hidraw` in the ouput. This is a shared object compiled by a vendor, so unfortunately I don't have the source code. Is this something I should contact the vendor about? – fortune Nov 20 '16 at 22:01
  • Yes, it has to be correctly linked against the dependency. Otherwise, I imagine you'd have to use ldpreload I fear. – codegrep_admin Nov 20 '16 at 22:06
  • Alright, thank you very much. This is all quite new to me. One follow up question: why doesn't explicitly loading the required library `hidapi-hidraw` have the same outcome as `LD_PRELOAD`? – fortune Nov 20 '16 at 22:16
  • 2
    With ldpreload you are essentially bypassing the linker and hence it will be loaded. I am on phone currently but you can potentially dlload from python instead of cdll to load the dependency – codegrep_admin Nov 20 '16 at 22:22