Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
593 views
in Technique[技术] by (71.8m points)

c++ - Libusb undefined reference to

I'm trying to set up libusb API on my OS. I downloaded libusb api on libusb.org. I followed the standard installation procedure:

cd into directory
./configure
make
make check //without errors
make install

Then I launched Eclipse C/C++ and copied some code from the tutorial found on the internet. But when trying to build it I got following output:

main.cpp:(.text+0x19): undefined reference to `libusb_init'
main.cpp:(.text+0x76): undefined reference to `libusb_set_debug'
main.cpp:(.text+0x8a): undefined reference to `libusb_get_device_list'
main.cpp:(.text+0x136): undefined reference to `libusb_free_device_list'
main.cpp:(.text+0x142): undefined reference to `libusb_exit'
/tmp/ccOWJGwe.o: In function `printdev(libusb_device*)':
main.cpp:(.text+0x162): undefined reference to `libusb_get_device_descriptor'
main.cpp:(.text+0x28a): undefined reference to `libusb_get_config_descriptor'
main.cpp:(.text+0x4d4): undefined reference to `libusb_free_config_descriptor'
collect2: ld returned 1 exit status

I have libusb.so in /lib and also I have usb.h in /usr/local/include and the link for the .so and libusb.a in /usr/local/lib.

Also the #include inside the code is correct.

I know that problem is in linker but I, kind of, cannot make it work :)

I'm using Fedora 15 operating system and gcc 4.6.0 20110603 (Red Hat 4.6.0-10) version compiler.

So what could I do to resolve these undefined references? Thanks very much for help :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I did face the same problem. But I was able to solve it by adding '-lusb-1.0' to the linker.

e.g : g++ myfile.cpp -lusb-1.0


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...