ollie299792458
ollie299792458

Reputation: 256

Compiler can't find installed library headers

Writing my first application in C and it can't seem to find the header file (which I installed following the instructions in the readme):

#include <stdio.h>
#include <stdlib.h>
#include <ftdi.h>

int main (int argc, char *argv[])
{
int ret;
struct ftdi_context = *ftdi;
struct ftdi_version_info version;
if ((ftdi = ftdi_new()) == 0)
{
    fprintf(stderr, "ftdi_new failed\n");
}
else {
    fprintf(stderr, "Success\n");
}
return 0;
}

But it finds it here:

ollieb@ursus ~/Documents/BitBang $ locate ftdi.h
/home/ollieb/.local/share/Trash/files/libftdi/libftdi/ftdipp/ftdi.hpp
/home/ollieb/.local/share/Trash/files/libftdi/libftdi/src/ftdi.h
/home/ollieb/Applications/libftdi1-1.3/build/doc/html/group__libftdi.html
/home/ollieb/Applications/libftdi1-1.3/build/doc/man/man3/ftdi.h.3
/home/ollieb/Applications/libftdi1-1.3/build/doc/man/man3/ftdi.hpp.3
/home/ollieb/Applications/libftdi1-1.3/ftdipp/ftdi.hpp
/home/ollieb/Applications/libftdi1-1.3/src/ftdi.h
/usr/include/libftdi1/ftdi.h
/usr/include/libftdi1/ftdi.hpp

This is what happens when I try to compile, it says the file cannot be found (when I run examples in the code library folder they run fine):

ollieb@ursus ~/Documents/BitBang $ make
make bitbang
make[1]: Entering directory '/home/ollieb/Documents/BitBang'
cc -Wall -g     bitbang.c   -o bitbang
bitbang.c:3:18: fatal error: ftdi.h: No such file or directory
compilation terminated.
<builtin>: recipe for target 'bitbang' failed
make[1]: *** [bitbang] Error 1
make[1]: Leaving directory '/home/ollieb/Documents/BitBang'
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 2

Upvotes: 3

Views: 3094

Answers (1)

Sourav Ghosh
Sourav Ghosh

Reputation: 134326

By default, compiler searches for the header files in the default INCLUDE path, not the whole filesystem.

If you have your headers in a custom path, you need to inform the compiler about that. For example, with gcc and clang, you can use the -I switch to let the compiler know the path where the header files are present.

From gcc online manual,

-Idir
Add the directory dir to the head of the list of directories to be searched for header files. [...]

Upvotes: 6

Related Questions