Skip to content

Link local libusb statically on Linux/Mac #283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed

Link local libusb statically on Linux/Mac #283

wants to merge 3 commits into from

Conversation

xlz
Copy link
Member

@xlz xlz commented Jun 10, 2015

Following discussions in #281.

This builds libusb-1.0.a into libfreenect2.so.

An issue with that is libfreenect2.so will export symbols that belong to libusb-1.0, then the users can't link libfreenect2 with anything that links with the system libusb-1.0 (symbol conflicts).

This works around the above issue by using GCC linker flag --exclude-libs,libusb-1.0.a. On Mac OSX, ld64 does not support such operation, with only one solution: generate all symbols, remove _libusb_* symbols, and specify non-libusb symbols with -exported_symbols_list,nolibusb.sym.

If anyone has better approach, please comment below. Static linking on Windows is a seperate PR.

@xlz
Copy link
Member Author

xlz commented Jun 16, 2015

@tikiking1 Does this PR work for your libfreenect2-git and pyfreenect2? Do they work correctly with static libusb?

@remexre
Copy link

remexre commented Jun 17, 2015

The Arch package builds fine, I'm updating it now. I don't actually have a Kinect 2 with me right now, but Protonect doesn't immediately segfault, so that's encouraging.

@remexre
Copy link

remexre commented Jun 17, 2015

And pyfreenect2 builds fine, but gets ImportError: /usr/lib/libfreenect2.so: undefined symbol: udev_device_get_devnode when I actually import it. Adding udev to the libraries section of setup.py doesn't fix it. It's a mystery?

@xlz
Copy link
Member Author

xlz commented Jun 17, 2015

It's a bug. Thanks for the catch.

libusb-1.0.a must come before -ludev, otherwise libudev is
ignored by linker because of lack of dependency.
@xlz
Copy link
Member Author

xlz commented Jun 17, 2015

The bug was caused by reversing the link order of libusb. Can you update and try again?

(The reason this bug was not detected by running Protonect is because Protonect pulled in libudev via some other libraries, while libfreenect2.so itself did not.)

@remexre
Copy link

remexre commented Jun 17, 2015

OK, it works now (in terms of getting an error because I don't have a Kinect with me, rather than because of a linking issue)

@floe floe added this to the 0.1 milestone Jun 24, 2015
@xlz xlz changed the title [RFC] Link local libusb statically on Linux/Mac Link local libusb statically on Linux/Mac Jul 18, 2015
@remexre
Copy link

remexre commented Jul 22, 2015

Is there a timeline for when this and #284 will get merged?

@floe
Copy link
Contributor

floe commented Jul 22, 2015

Not really, although I'm hoping I'll get around to it sometime next week. Problem is that there may still be some interference with #292.

@xlz
Copy link
Member Author

xlz commented Jul 22, 2015

#292 is fairly easy to code up. The issue is a decision has to be made.

@xlz
Copy link
Member Author

xlz commented Aug 23, 2015

I start to think embedded static libusb in libfreenect2 is a bad idea. The hack of messing with export symbols was not a good idea from the outset and can easily break. Besides, it is really not up to libfreenect2 to decide where to install libusb, or to embed it.

For packagers, I think the best option is to carry a separate libusb.so in a private directory of the package you want to release and change RPATH of libfreenect2 to that directory. chrpath can do that job post hoc. If you know the install directory before building, -DCMAKE_INSTALL_RPATH=... will do that too (not right now; need a quick patch).

@xlz
Copy link
Member Author

xlz commented Aug 25, 2015

I have created a patch for specifying custom RPATH https://github.com/xlz/libfreenect2/commit/7a4708fa03d528ff9339c2c7034515e44861561a. It is expected to be part of a future PR soon.

@xlz xlz closed this Aug 25, 2015
@xlz xlz deleted the static-libusb branch November 18, 2015 11:44
@xlz xlz restored the static-libusb branch November 18, 2015 11:44
@xlz xlz deleted the static-libusb branch December 4, 2015 02:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants