How do I link a simple example project to libusb?

你离开我真会死。 提交于 2019-12-11 19:01:32

问题


I'm trying to make use of LibUSB to interact with a small programmable LED device I've built. I have working code on Windows using the libusb-win32 port but I'm having trouble porting this to the MAC.

I've cloned LibUSB to a local git repository and compiled it using XCode I think is the preferred method on the MAC. After a bit of digging (including showing the hidden Library folder), it looks like XCode outputs to /Users/jon/Library/Developer/Xcode/DerivedData/libusb-ekndohtauywugtgjlolqmmdyoafq/Build/Products/Debug/libusb-1.0.0.dylib.

So my question is, how can I create a simple console application in XCode (or something else if there's an easier way of doing this) which links in that library and calls a function from the libusb library (e.g. libusb_init(libusb_context **ctx);)?


回答1:


Rather than building libusb from scratch using Xcode you should probably just build it in the conventional way (as you would on e.g. Linux), or better yet, install it pre-built from Homebrew or MacPorts. Then just add the relevant header and library to your Xcode project in the normal way.

See also: How to set up libusb on Mac OS X?.




回答2:


I have been frustrated for several days now trying to use libusb in my Xcode project. It started simple enough: 1. download libusb-1.0.20 from github; 2. run .configure, .make and .install - no errors; 3. drag libusb.dylib from /usr/local/lib into my project selecting copy options. Xcode automatically adds libusb.dylib to the Linked Frameworks and Libraries; 4. drag libusb.h from the build directory into my project

Project would build and run without errors until I submitted the app to the app store. Then I learned that dlopen is attempting to load from /usr/local/lib/libusb.dylib. Also, Xcode only copies the dylib file to my target bundle if I explicitly add it to the Copy Files Build Phase.

After reading through tons of documentation for something that should be easy, I find no simple way to have dlopen load the library from my app bundle. Store apps must be complete. They cannot users to already have libusb installed on their system.

Thanks, Bob Rice



来源:https://stackoverflow.com/questions/27184357/how-do-i-link-a-simple-example-project-to-libusb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!