开发者

Including a library (lsusb) in a C program

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 p开发者_如何学JAVAorts on a hub I have. That is, however, not the issue I am having right now.

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?


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

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.

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.


See the "-I" parameter in the gcc man page. It allows you specify a directory in which to find a header file. See also -l and -L.


Or try #include "../../path_to_the_file/lsusb.h"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜