简体   繁体   中英

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 ports 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.

或尝试#include“ ../../path_to_the_file/lsusb.h”

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM