Including a library (lsusb) in a C program

I'm still pretty new to C programming, and I'm working on a program where I want to control the power of various ports on a hub that I have. This, however, is not a problem that I am currently facing.

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

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

0
source share
3 answers

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

The brackets around the include file ( <> ) indicate that you want the compiler to search for a standard search path for the include file. Thus, you can access this new include file either by placing it in a directory on your standard file search path, or by adding its directory to the file search path. With GCC, you do the latter by providing the gcc flag -I"directoryname" , where "directory_name" is the full path to the file where you store this new include file.

Once your compiler finds this, your linker may have the same problem with the library file itself ("liblsusb.a"?). You are correcting the same. The GCC linker flag will need -L instead of -I .

+2
source

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

+1
source

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

0
source

Source: https://habr.com/ru/post/1011928/


All Articles