Libusb未定义引用 [英] Libusb undefined reference to

查看:3274
本文介绍了Libusb未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的操作系统上设置libusb API。我在libusb.org上下载了libusb api。我按照标准安装程序:

  cd到目录
./configure
make
make check //没有错误
make install

然后我启动了Eclipse C / C ++并复制一些从互联网上找到的教程的代码。但是当尝试构建它时,我得到以下输出:

  main.cpp :(。text + 0x19):undefined引用` libusb_init'
main.cpp :( .text + 0x76):未定义的引用`libusb_set_debug'
main.cpp :( .text + 0x8a):未定义引用`libusb_get_device_list'
main。
main.cpp :(。text + 0x142):未定义的引用`libusb_exit'
/tmp/ccOWJGwe.o:在函数` printdev(libusb_device *)':
main.cpp :( .text + 0x162):未定义引用`libusb_get_device_descriptor'
main.cpp :(。text + 0x28a):未定义引用`libusb_get_config_descriptor'
main.cpp :(。text + 0x4d4):未定义引用`libusb_free_config_descriptor'
collect2:ld返回1退出状态

我在/ lib中有libusb.so,在/ usr / local / include中有usb.h,在/ usr / local / lib中有.so和libusb.a的链接。



代码中的#include是正确的。



我知道问题是在链接器, ,种类,不能使它工作)



我使用Fedora 15操作系统和gcc 4.6.0 20110603(Red Hat 4.6.0-10)版本编译器。



那么我该如何解决这些未定义的引用?非常感谢帮助:)

解决方案

您必须在链接器中设置库链接器标记
您可以在控制台中通过执行



pkg-config --list-all



这些是您在系统上安装的库,您必须链接到要使用的库。
所以在你的例子中它是libusb所以你做



pkg-config --libs libusb



应该有输出



-lusb / p>

这样就给你传递给链接器的标志。



然后编辑项目的配置并搜索linkerflags,在buildoptions的某处应该有一个文本字段。我不太确定在哪里可以找到它,但谷歌为它建议:



项目 - >属性 - > C / C ++
Build - >杂项 - > flags

$



找到后,只需在文本字段中添加链接器标记即可。


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 :)

解决方案

you have to set the library linker flag for compilation in the linker, you can get a full list in the console by executing

pkg-config --list-all

These are the libraries which you have installed on your system and you have to link against the ones you want to use. so in your example it is libusb so you do

pkg-config --libs libusb

there should be the output

-lusb

This gives you the flag you have to pass to the linker.

Then you edit the configuration of the project and search for the linkerflags, there should be a textfield for that somewhere in the buildoptions. i'm not quite shure where to find it but googling for it suggested:

Project -> Properties -> C/C++ Build -> Miscellaneous -> flags

After you found it, just add the linker flag in the textfield and you should be fine.

这篇关于Libusb未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆