2

We are using swig to add python bindings to out c++ library. I have created the .i file and compile the swig generated output into the library.

However when trying and use our library from within Python, the following error occurs:

ImportError: /home/satpal/src/alpha/USBDrDaq/examples/libUSBDrDAQ.so: undefined symbol: libusb_clear_halt

As you can see the library uses LibUSB. the .i file has an include for libusb.h, this doesn't seem to be enough.

Is Python going to need bindings for libUSB aswell?

Satpal
  • 309
  • 2
  • 8

1 Answers1

3

You need to link libUSB into the shared library that you are producing. That is, the command line that builds your shared library should be something like this:

gcc -shared example.o example_wrap.o -o _example.so -lusb

Note the -lusb at the end.

HighCommander4
  • 50,428
  • 24
  • 122
  • 194
  • Thanks for this. Realiser this was the case, having just run nm -u on the shared library. However I'm unsure of how to add this to my autoconf/automake projects, makefile.am – Satpal May 28 '12 at 10:42
  • 2
    @Satpal assuming libtool `lib_example_la_LIBADD=-lusb` in Makefile.am would do it. – Flexo May 29 '12 at 08:45
  • why is it so critical that the -lusb is at the end? I note it fails if it isn't – bph Oct 19 '15 at 15:36
  • 1
    @bph: See http://stackoverflow.com/questions/45135/why-does-the-order-in-which-libraries-are-linked-sometimes-cause-errors-in-gcc – HighCommander4 Oct 20 '15 at 00:57