Cannot find -lusb in opensuse 12.2

I am compiling a program under opensuse 12.2 with the following build rule,

$(BDIR)/suse_test_app: $(OBJSS)
$(CC++) $(OPTIMIZE) -o $@ $(FCFLAGS) $(OBJSS) -lusb -lpthread

I am getting a linker error,
cannot find -lusb

I have the usb devel lib (libusb-1_0-devel) installed in yast, so I'm not sure why I am getting this error. Does the library have a different name under suse?
According to yast, the files are here,
/usr/include/libusb-1.0
/usr/include/libusb-1.0/libusb.h
/usr/lib64/libusb-1.0.so

I have checked and all of that is where it is supposed to be. Can someone let me know how to fix this. Do I need to create a link somewhere that will let make know where the library is?

LMHmedchem

The .so file is not enough, you need the .a file to link.

I'd expect the .so to be part of libusb, not libusb-devel. Make sure you have both installed.

1 Like

Where would I look to make sure that the .a file is where it is supposed to be?

I have the following installed for usb,

libusb-0_1-4 - libusb-1.0 Compatibility Library for libusb-0.1

/usr/lib64/libusb-0.1.so.4
/usr/lib64/libusb-0.1.so.4.4.4
/usr/share/doc/packages/libusb-0_1-4
/usr/share/doc/packages/libusb-0_1-4/AUTHORS
/usr/share/doc/packages/libusb-0_1-4/COPYING
/usr/share/doc/packages/libusb-0_1-4/ChangeLog
/usr/share/doc/packages/libusb-0_1-4/LICENSE
/usr/share/doc/packages/libusb-0_1-4/NEWS
/usr/share/doc/packages/libusb-0_1-4/README

libusb-1_0-0 - USB Library

/usr/lib64/libusb-1.0.so.0
/usr/lib64/libusb-1.0.so.0.1.0
/usr/share/doc/packages/libusb-1_0-0
/usr/share/doc/packages/libusb-1_0-0/AUTHORS
/usr/share/doc/packages/libusb-1_0-0/COPYING
/usr/share/doc/packages/libusb-1_0-0/NEWS
/usr/share/doc/packages/libusb-1_0-0/README
/usr/share/doc/packages/libusb-1_0-0/THANKS
/usr/share/doc/packages/libusb-1_0-0/TODO

libusb-1_0-devel - USB Library

/usr/include/libusb-1.0
/usr/include/libusb-1.0/libusb.h
/usr/lib64/libusb-1.0.so
/usr/lib64/pkgconfig/libusb-1.0.pc
/usr/share/doc/packages/libusb-1_0-devel
/usr/share/doc/packages/libusb-1_0-devel/PORTING

libusbmuxd2 - A library to abstract socket/protocol communication to the usbmuxd daemon

/usr/lib64/libusbmuxd.so.1.0.8
/usr/lib64/libusbmuxd.so.2

If I change my link line to,
$(BDIR)/suse_test_app: $(OBJSS)
$(CC++) $(OPTIMIZE) -o $@ $(FCFLAGS) $(OBJSS) -lusb-1.0 -lpthread

I can get the app to link. There is a segfault at runtime, so I don't know if the above is linking to the proper library or not. I just assumed that -lusb was referring to a devel element, but I guess it makes more sense that it would be a runtime element, since users wouldn't have the devel library installed.

LMHmedchem

The development library is what's supposed to allow you to link to the library but generally isn't the library itself.

The devel library looks weird. It installs headers but doesn't install symbols. I suspect the "/usr/lib64/libusb-1.0.so" it installs is a symlink, and if it isn't, why on earth is it installing a third version of libusb? That may be the reason for the crash, linking one version and loading another.

I see it includes a file for pkgconfig, so you can do pkg-config --ldflags libusb-1.0 to see how it's supposed to be linked. If it doesn't work, I suspect there's files actually missing.

If I do pkg-config --ldflags libusb-1.0 in bash, I get an error, --ldflags: unknown option. I could add $(pkg-config --ldflags libusb-1.0) to the link rule instead of -lusb, but I don't think that is going to do anything if it fails in bash.

LMHmedchem

Pardon me, --libs.

Running pkg-config --libs libusb-1.0 gives -lusb-1.0, which is what I ended up using to get it to compile.

I have compiled with this, but the app will still not work. It is possible that I have some other error in there that I need to find. How could I go about finding if the .a file is where it is supposed to be?

LMHmedchem

pkg-config --cflags also gives you the include paths and such to compile. Hopefully that'll force it to use the right definitions for the one of the three --libs picks.

1 Like

Well it does seem to link properly using -lusb-1.0 and I have it working now. There appear to have been some changes in the way this hardware works and I may not actually have to link to the usb lib anymore, go figure.

Thanks again for the help, I'm sure that learning about pkg-config will continue to prove useful.

LMHmedchem

Try ldd ./myprogram to see what libraries it loads, I suspect it does actually load one of your libusb so files.

This is the list of libs that are loaded,
linux-vdso.so.1 (0x00007fffd1595000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f85ac109000)
libusb-1.0.so.0 => /usr/lib64/libusb-1.0.so.0 (0x00007f85abef9000)
libstdc++.so.5 => /usr/lib64/libstdc++.so.5 (0x00007f85abc17000)
libm.so.6 => /lib64/libm.so.6 (0x00007f85ab919000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f85ab703000)
libc.so.6 => /lib64/libc.so.6 (0x00007f85ab355000)
/lib64/ld-linux-x86-64.so.2 (0x00007f85ac325000)
librt.so.1 => /lib64/librt.so.1 (0x00007f85ab14d000)

I'm not sure this tells me if my app is using anything in the library or not because I linked to the usb library in make. If I have -lusb-1.0 in my link rule, will libusb-1.0 appear on this list even if there is never anything in the library that gets called?

I guess I probably need to build it without the link and see if it still works.

LMHmedchem

If you leave out -lusb-1.0 and it still links, then you are correct.