fortune fortune - 10 months ago 56
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

. The latter is dependent on the former.

from ctypes import *

hidapi = CDLL('/home/wsharp/Source/pyprox/')
pcProxAPI = CDLL('/home/wsharp/Source/pyprox/')

r = pcProxAPI.usbConnect()

If I run
I receive the following error: "undefined symbol: hid_send_feature_report"

However if I run
>LD_PRELOAD=./ python
I don't receive any issues.

I've tried placing the
and other paths sourced by
with no luck. I'm not sure what I'm doing wrong, but it's driving me nuts. Any help would be appreciated.


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

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


ldd => (0x00007fff9d3b9000) => /usr/lib/x86_64-linux-gnu/ (0x00007f276c231000) => /lib/x86_64-linux-gnu/ (0x00007f276bf28000) => /lib/x86_64-linux-gnu/ (0x00007f276bd11000) => /lib/x86_64-linux-gnu/ (0x00007f276b948000)
/lib64/ (0x000055dfcf780000)

Answer Source

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/ and run ldconfig - (need root)