在C程序中包含一个库(lsusb) [英] Including a library (lsusb) in a C program

查看:135
本文介绍了在C程序中包含一个库(lsusb)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于使用C进行编程,我还是一个新手,我正在开发一个程序,该程序要控制我拥有的集线器上各个端口的电源.但是,那不是我现在遇到的问题.

I am still fairly new to programming with C and I am working on a program where I want to control the power to various ports on a hub I have. That is, however, not the issue I am having right now.

我在网上找到了一个程序,该程序可以完成我想编译的程序.但是,它使用#include<lsusb.h>. lsusb与我要运行的文件位于一个完全不同的文件夹中(而不是子文件夹中),并且当我尝试对其进行编译时,从逻辑上来说,我得到的错误是找不到文件lsusb.h.

I found a program online that does what I want I am trying to compile it. However it uses #include<lsusb.h>. lsusb is located in a totally different folder than the file I am wanting to run (and not in a sub folder) and when I try to compile it, I, logically enough, get the error that the file lsusb.h is not found.

如何链接到该文件以便可以找到它?

How can I link to this file so that it can be found?

推荐答案

这比C问题更像是GCC工具链问题(尽管大多数C编译器确实使用相同的Unixy标志).

This is more of a GCC toolchain question than a C question (although most C compilers do use the same Unixy flags).

包含文件(<>)周围的花括号表示您希望编译器在其标准搜索路径中搜索包含文件.因此,您可以通过自己将其包含在标准包含文件搜索路径中的目录中,或将其目录添加到文件搜索路径中来访问该新包含文件.使用GCC,您可以通过给gcc标记-I"directoryname"来实现后者,其中目录名"是您保留新的包含文件的完整文件路径.

The braces around the include file (<>) indicate you want the compiler to search its standard search path for the include file. So you can get access to that new include file either by putting it into a directory on your standard include file search path yourself, or by adding its directory to the file search path. With GCC you do the latter by giving gcc the flag -I"directoryname" where "directoryname" is the full file path to where you are keeping that new include file of yours.

一旦编译器找到它,则链接器可能与库文件本身完全相同("liblsusb.a"?).您以相同的方式修复. GCC的链接器将需要的标志是-L而不是-I.

Once your compiler finds it, your linker may have the exact same problem with the library file itself ("liblsusb.a"?). You fix that the same way. The flag GCC's linker will want is -L instead of -I.

这篇关于在C程序中包含一个库(lsusb)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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