fortune fortune - 16 days ago 7
Linux Question

Library will only load with LD_PRELOAD

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)

Answer

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)