在Mac OS X中链接libusb

编程入门 行业动态 更新时间:2024-10-21 23:01:55
本文介绍了在Mac OS X中链接libusb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有这个非常简单的代码,我试图编译。我对命令行 GCC 相当陌生,所以请原谅我。我已经用GCC尝试了很多不同的东西,但我仍然无法编译它。我确实安装了 libusb 。如何获得这段代码进行编译?

Libusb:

anything:usb mymac $ brew list libusb /usr/local/Cellar/libusb/1.0.9/include/libusb-1.0/libusb.h /usr/local/Cellar/libusb/1.0 .9 / lib / libusb-1.0.0.dylib /usr/local/Cellar/libusb/1.0.9/lib/pkgconfig/libusb-1.0.pc / usr / local / Cellar / libusb /1.0.9/lib/(2个其他文件)任何东西:usb mymac $

GCC尝试(全部失败):

gcc -o xout usbtest.c gcc -o xout usbtest.c - lusb-1.0 gcc -L / usr / local / Cellar / libusb / 1.0.9 / lib -o xout usbtest.c -lusb-1.0

所有尝试的错误:

usbtest.c:3:10:致命错误:找不到'libusb.h'文件 #include< libusb.h>

代码:

#include< stdio.h> #include< stdlib.h> #include< libusb.h> int main(int argc,const char * argv []) { libusb_device ** devs; libusb_context * context = NULL; size_t list; // size_t i; int ret; ret = libusb_init(& context); if(ret <0) { perror(libusb_init); exit(1); } list = libusb_get_device_list(context,& devs); printf(有%zd设备找到了\ n,列表); 返回0;

解决方案

查找头文件。这是通过gcc命令行上的 -I 选项进行编译的。

eg

gcc -I / usr / local / include -o xout usbtest.c

我认为Homebrew确实提供了从酒窖内部到/ usr / local 的符号链接

I have this very simple piece of code that I'm trying to compile. I'm fairly new to GCC from the command line, so please forgive me. I've tried a quite few different things with GCC, but I'm still unable to get it to compile. I do have libusb installed. How can I get this piece of code to compile?

Libusb:

anything:usb mymac$ brew list libusb /usr/local/Cellar/libusb/1.0.9/include/libusb-1.0/libusb.h /usr/local/Cellar/libusb/1.0.9/lib/libusb-1.0.0.dylib /usr/local/Cellar/libusb/1.0.9/lib/pkgconfig/libusb-1.0.pc /usr/local/Cellar/libusb/1.0.9/lib/ (2 other files) anything:usb mymac$

GCC attempts (all failed):

gcc -o xout usbtest.c gcc -o xout usbtest.c -lusb-1.0 gcc -L/usr/local/Cellar/libusb/1.0.9/lib -o xout usbtest.c -lusb-1.0

Error for all attempts:

usbtest.c:3:10: fatal error: 'libusb.h' file not found #include <libusb.h>

Code:

#include <stdio.h> #include <stdlib.h> #include <libusb.h> int main(int argc, const char * argv[]) { libusb_device **devs; libusb_context *context = NULL; size_t list; //size_t i; int ret; ret = libusb_init(&context); if(ret < 0) { perror("libusb_init"); exit(1); } list = libusb_get_device_list(context, &devs); printf("There are %zd devices found\n", list); return 0; }

解决方案

You are not telling gcc where to look for the header files. This is done by the -I option on the gcc command line for compiling.

e.g.

gcc -I /usr/local/include -o xout usbtest.c

I think Homebrew does provide a symbolic link frominside the Cellar to /usr/local

更多推荐

在Mac OS X中链接libusb

本文发布于:2023-10-07 15:21:14,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:链接   Mac   OS   libusb

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!