Author Topic: libusb and Eclipse noob question.  (Read 12076 times)

Martin

  • Member
  • ***
  • Posts: 5
libusb and Eclipse noob question.
« on: July 26, 2014, 10:12:50 pm »
Hi All.

I'm still learning how to do things in a  Linux environment, and I want to compile the generic_hid example using Eclipse. I can do this without issue from the command line, but I cant figure out how to pass the -lusb-1.0 option to Eclipse.

On the command line I use:
gcc -o ghid generic_hid.c -I/usr/include/libusb-1.0/ -lusb-1.0
which works fine.

Can anyone help out with this?  I noticed a search on this site using eclipse as a key work did not reveal much. Is anyone else using Eclipse to do the same?

Cheers
m.b

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: libusb and Eclipse noob question.
« Reply #1 on: July 27, 2014, 10:52:07 am »
Add the path to the project’s Include paths.

Martin

  • Member
  • ***
  • Posts: 5
Re: libusb and Eclipse noob question.
« Reply #2 on: July 27, 2014, 07:57:21 pm »
hmm... I wasn't expecting that...  -lusb, or -lusb-1.0 still wont work within eclipse. Fair enough though, a path in the windows world is the fix for all ailments for sure.

I came across a post which advised someone to plug in the "pkg-config --libs libusb" command and then use its output “-lusb” to plug back into the linker,.. tried that still failed.  Any ideas?

m.b

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: libusb and Eclipse noob question.
« Reply #3 on: July 27, 2014, 09:45:48 pm »
By "failed," do you mean that you were able to include the path without error but the project didn't compile? What was the error?

Martin

  • Member
  • ***
  • Posts: 5
Re: libusb and Eclipse noob question.
« Reply #4 on: July 28, 2014, 01:09:39 am »
Hi Jan, thanks for your input even though its not directly a USB issue.

I've just (as I write this) successfully compiled my eclipse project). Long story short I was actually correctly adding the -lusb linker command, and also correctly adding the path to the library files. But,...... lesson to oneself, don't add “-lusb” to the libraries section within C++ build settings, but leave out the “-l” in other words add it as “usb” or “usb-1.0”, it seems the “-l” is added internally. At least this is what worked.
Who knew? not me.

BTW:

The error was,

../src/generic_hid.cpp:78: undefined reference to `libusb_init'

and the same type of error for all libusb function your example uses.
Let me know if you want me to elaborate on my steps taken.


Cheers
m.b

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: libusb and Eclipse noob question.
« Reply #5 on: July 28, 2014, 08:48:02 am »
Glad you got it working; thanks for reporting back.