82

How to add multiple header include and library directories to the search path in a single gcc command?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Bingo
  • 3,785
  • 6
  • 23
  • 27

3 Answers3

128

Use multiple -I flags for the include directories and multiple -L flags for the lib directories

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
  • 4
    Does using -I/path/to/dir/ include all the header files in the sub directories present in /path/to/dir/ also? – Vishnu N K Nov 14 '17 at 10:11
45

You can set the C_INCLUDE_PATH environment variable.

export C_INCLUDE_PATH=.:/some/dir:/some/other/dir

as well as the LIBRARY_PATH environment variable.

Brian Roach
  • 76,169
  • 12
  • 136
  • 161
24

On Linux you need to use -I before each directory that you want to add.

Example:

user:/home/my_project$ gcc -g -Wall -I/usr/include/lib_Directory/ -I./include -c ./src/transcod.c

./ means the current directory where you are running the command, in this case my_project;

Jeff Pal
  • 1,519
  • 1
  • 17
  • 28