0

How can I reference a class/framework/library like libusb in an Objective-C class?

Currently I have tried to initiate an enum/struct-function from the library inside my @interface in my .h-file.
But that doesn't work, apparently. :/
I have it "installed" (it's in /usr/local), and tried adding both the files and as framework. Doesn't help, though.

johankj
  • 1,765
  • 16
  • 34

2 Answers2

0
  1. Copy libusb to your project.
  2. Add #include lines.
mcandre
  • 22,868
  • 20
  • 88
  • 147
0

Chances are that you haven't added /usr/local/include and /usr/local/lib to the search paths in your project. In Xcode, bring up either the project settings or the target settings and look for a section named "Search Paths". Double-click on "Header Search Paths" and add /usr/local/include. Now, double-click on "Library Search Paths" and add /usr/local/lib. When you rebuild your project, libusb should be available. You will need to add #include <libusb.h> at the top of each source file that uses functionality from that product.

Apple makes a distinction between libraries and frameworks. A library is what you have now. There are header files and library (dylib) files that you compile and link against. They are stored in somewhat global locations, such as /usr/include, /usr/local/include, and so-forth. Frameworks are bundles that contains headers, libraries, graphical resources, version information, and more.

Paul
  • 2,698
  • 22
  • 27
  • But how can I declare a variable/device in the @implentation ? `static struct libusb_device_handle *device = NULL;` gives the following error: `xpected specifier-qualifier-list before 'static'` – johankj Jun 28 '10 at 12:39
  • I believe `libusb_device_handle` is a typedef. Remove the `struct` from that line and it will likely work as expected. If the compiler still cannot find the type, you probably don't have the `#include ` at the top of you implementation file. – Paul Jun 29 '10 at 12:46
  • I still get the same error. The compiler doesn't complain that the file doesn't exist where as it does with , so I guess I have it included. – johankj Jul 01 '10 at 09:50
  • That's because your compiler is looking at `/usr/local/include` and you need to specify `` as the library installed its headers under a subdirectory with that name. What version of OS X are you compiling on? Which version of GCC or LLVM are you using? What do your project settings look like? – Paul Jul 01 '10 at 14:45
  • I've added /usr/local/include/libusb-1.0/ to the "Header Search Paths" but still won't work. Any chance of you uploading an example? (That'll probably be faster) – johankj Jul 01 '10 at 19:35
  • You should really add `/usr/local/include` to the header search path and add the last level into your include statement as: `#include ` Since you're the one asking the question, it would be helpful if you upload some source and your project settings, as was already requested. – Paul Jul 02 '10 at 13:02
  • I followed your instructions and it worked well. However, there are one more step to make it link: I had to add "-l" to the "Other Linker Flags" of the project target build options. I've got some other problems because I am using a library of mine but I bet that this issues are not relevanto to these example. – brandizzi Feb 26 '11 at 16:45