1
votes

I'm aware that when using #include <file> the compiler will search in defined system directories for file. How can I view these directories?

I ask because I added a directory with a bunch of header files into /usr/local/include, and when I #include <file> the compiler still says error: unknown type name ‘TPM_TAG’. I suspect that /usr/local/include isn't in the compiler's list of directories to search.

Thanks!

4
If the file wasn't found you would have a fatal error so that is not the problemaaronman
You can use the -I flag to pass include directories.devnull
He might still have an instance of a header file in /usr/include, and a newer version in /usr/local/include.Guntram Blohm
It depends on what compiler you're using. With gcc, gcc -v should show you where it's looking.Keith Thompson
I have a directory full of header files that I want to use in my project. These header files assume that they are in a directory recognized by gcc (because they include each other with #include <file>). So I put this directory in /usr/local/include and included them with #include<file>, and I get the unknown type name error. I tried removing my #include statement to see what would happen, and I got the same error. This makes me think the compiler is not finding the directory of header files in /usr/local/include. @KeithThompson, which option of that output provides the directory?Rob

4 Answers

1
votes

You can search in different ways depending on the compiler, with gcc for example it is possible to check where the compiler looks for files by using

gcc -print-search-dirs

or you can compile your c file with the option gcc -H, for example with gcc -H -c myfile.c

0
votes

It depends if you're using a standard header or a local, user-defined header. Maybe try to use #include "file" and make the header file local instead and see if that works?

0
votes
gcc -I. yourfile.c 

-I introduce path of include files, So if you have some include file in your subdirectory such as sort/ list/ and so on,you should behave shuch as:

gcc -I. -I./list -I./sort myfile.c

NOTE: Please consider use "" for your header files and use <> for system header files.such as :

#include <iostream>
#include "myheader.h"
0
votes

The compiler ships with a lot of *.h files that depend on its exact configuration. Take a look at this question too. A general way to convince GCC/clang to own up is:

echo | gcc -E -Wp,-v -

(replace gcc with clang as needed).