Home  >  Article  >  Backend Development  >  How do I tell GCC to search for header files in specific directories?

How do I tell GCC to search for header files in specific directories?

Patricia Arquette
Patricia ArquetteOriginal
2024-10-30 02:02:02354browse

How do I tell GCC to search for header files in specific directories?

Including Header Files in GCC Search Path

When working with complex codebases spread across multiple folders, one may encounter issues with GCC locating the required header files for compilation. This guide addresses the specific problem faced by the user in including header files from various subdirectories within a larger project directory.

To instruct GCC to search for header files in a specific path, the -I flag is employed. The syntax is as follows:

gcc -I<path> <source file>

For the given code example with header files located under /home/me/development/skia, the proper compilation command would be:

gcc -c -I/home/me/development/skia sample.c

With this flag, GCC will search for the header files in /home/me/development/skia and its subdirectories, allowing the code to be compiled successfully.

The above is the detailed content of How do I tell GCC to search for header files in specific directories?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn