1

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!

Rob
  • 430
  • 1
  • 5
  • 13
  • 4
    If the file wasn't found you would have a fatal error so that is not the problem – aaronman Feb 24 '14 at 19:22
  • You can use the `-I` flag to pass include directories. – devnull Feb 24 '14 at 19:23
  • He might still have an instance of a header file in /usr/include, and a newer version in /usr/local/include. – Guntram Blohm Feb 24 '14 at 19:23
  • 4
    It depends on what compiler you're using. With gcc, `gcc -v` should show you where it's looking. – Keith Thompson Feb 24 '14 at 19:24
  • 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 `). So I put this directory in /usr/local/include and included them with `#include`, 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 Feb 24 '14 at 21:15
  • In the output of `gcc -v` look for "`#include "..." search starts here:`" and "`#include <...> search starts here:`". You can also examine the preprocessor output produced by `gcc -E` to see exactly which files are included. As I said, this depends on what compiler you're using; if you're looking for information about gcc in particular, please update your question to say so and add the "gcc" tag. – Keith Thompson Feb 24 '14 at 21:22

4 Answers4

1

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

Jekyll
  • 1,434
  • 11
  • 13
0

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
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"
PersianGulf
  • 2,845
  • 6
  • 47
  • 67
  • He's not asking how to include some file, but how to view the directories the compiler is searching when you include a file using the `#include ` directive – Praetorian Feb 24 '14 at 19:29
0

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

Community
  • 1
  • 1
vonbrand
  • 11,412
  • 8
  • 32
  • 52