c++ - libusb 在 IDE 中不可见

标签 c++ c ubuntu codeblocks libusb

我在 Ubuntu Linux 中使用代码块。我想用库 libusb 编写程序。我在系统中有这个文件,但是IDE中的编译器找不到这个文件。我在“构建选项”中添加了这个文件,但没有帮助。这个问题的解决方案是什么?

#include <libusb.h>

更新:

dpkg -L libusb-dev显示如下:

/.
/usr
/usr/bin
/usr/bin/libusb-config
/usr/include
/usr/include/usb.h
/usr/lib
/usr/lib/libusb.a
/usr/lib/libusb.la
/usr/lib/pkgconfig
/usr/lib/pkgconfig/libusb.pc
/usr/share
/usr/share/doc
/usr/share/doc/libusb-dev
/usr/share/doc/libusb-dev/changelog.gz
/usr/share/doc/libusb-dev/html
/usr/share/doc/libusb-dev/html/index.html
/usr/share/doc/libusb-dev/html/preface.html
/usr/share/doc/libusb-dev/html/intro.html
/usr/share/doc/libusb-dev/html/intro-overview.html
/usr/share/doc/libusb-dev/html/intro-support.html
/usr/share/doc/libusb-dev/html/api.html
/usr/share/doc/libusb-dev/html/api-device-interfaces.html
/usr/share/doc/libusb-dev/html/api-timeouts.html
/usr/share/doc/libusb-dev/html/api-types.html
/usr/share/doc/libusb-dev/html/api-synchronous.html
/usr/share/doc/libusb-dev/html/api-return-values.html
/usr/share/doc/libusb-dev/html/functions.html
/usr/share/doc/libusb-dev/html/ref.core.html
/usr/share/doc/libusb-dev/html/function.usbinit.html
/usr/share/doc/libusb-dev/html/function.usbfindbusses.html
/usr/share/doc/libusb-dev/html/function.usbfinddevices.html
/usr/share/doc/libusb-dev/html/function.usbgetbusses.html
/usr/share/doc/libusb-dev/html/ref.deviceops.html
/usr/share/doc/libusb-dev/html/function.usbopen.html
/usr/share/doc/libusb-dev/html/function.usbclose.html
/usr/share/doc/libusb-dev/html/function.usbsetconfiguration.html
/usr/share/doc/libusb-dev/html/function.usbsetaltinterface.html
/usr/share/doc/libusb-dev/html/function.usbresetep.html
/usr/share/doc/libusb-dev/html/function.usbclearhalt.html
/usr/share/doc/libusb-dev/html/function.usbreset.html
/usr/share/doc/libusb-dev/html/function.usbclaiminterface.html
/usr/share/doc/libusb-dev/html/function.usbreleaseinterface.html
/usr/share/doc/libusb-dev/html/ref.control.html
/usr/share/doc/libusb-dev/html/function.usbcontrolmsg.html
/usr/share/doc/libusb-dev/html/function.usbgetstring.html
/usr/share/doc/libusb-dev/html/function.usbgetstringsimple.html
/usr/share/doc/libusb-dev/html/function.usbgetdescriptor.html
/usr/share/doc/libusb-dev/html/function.usbgetdescriptorbyendpoint.html
/usr/share/doc/libusb-dev/html/ref.bulk.html
/usr/share/doc/libusb-dev/html/function.usbbulkwrite.html
/usr/share/doc/libusb-dev/html/function.usbbulkread.html
/usr/share/doc/libusb-dev/html/ref.interrupt.html
/usr/share/doc/libusb-dev/html/function.usbinterruptwrite.html
/usr/share/doc/libusb-dev/html/function.usbinterruptread.html
/usr/share/doc/libusb-dev/html/ref.nonportable.html
/usr/share/doc/libusb-dev/html/function.usbgetdrivernp.html
/usr/share/doc/libusb-dev/html/function.usbdetachkerneldrivernp.html
/usr/share/doc/libusb-dev/html/examples.html
/usr/share/doc/libusb-dev/html/examples-code.html
/usr/share/doc/libusb-dev/html/examples-tests.html
/usr/share/doc/libusb-dev/html/examples-other.html
/usr/share/doc/libusb-dev/copyright
/usr/share/doc/libusb-dev/changelog.Debian.gz
/usr/share/doc-base
/usr/share/doc-base/libusb-dev
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/libusb-config.1.gz
/usr/lib/libusb.so

但是当我改变#include <libusb.h>#include <usb.h>并尝试编译这段代码:

#include <stdio.h>
#include <stdlib.h>
#include <usb.h>
int main(){
    usb_init();
    printf("Hello world!\n");
    return 0;
}

我收到以下错误:

undefined reference to 'usb_init'

最佳答案

似乎缺少 libusb-dev

或者

执行dpkg -L libusb-dev 列出libusb-dev 包中的所有文件,找出合适的包含文件名及其位置。您很可能最终会将包含更改为:

#include <usb.h>

此外,仅向程序添加标题是不够的 - 您需要显示应该链接哪个库以使用标题中声明的那些符号。将以下内容添加到您的编译器选项:

-lusb

关于c++ - libusb 在 IDE 中不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7473978/

相关文章:

ubuntu - gpsd:error: can't run with both control socket and devices on petalinux

具有嵌套表达式模板的 C++ 类

c - 在 C 结构体中存储字符串

c - 使用泰勒级数求 C 中的 sin(x)

objective-c - 我是否需要释放 Objective-C 代码中的 C 变量(带有 ARC 的 iOS 6)?

git - 如何在 Apache 和子域或不同路径上安装 Gitlab

java - 线程 “main” 中的异常 java.util.IllegalFormatConversionException : g ! = java.lang.String

c++ - 基本值(value)交换功能

c++ - 不确定这段代码在做什么

c++ - 如何从 vector<char> 获取 char *?