0

i know there a a few posts already about this but I do not seem to be able to get it right.

I am working on a shared project using geany and gcc. The file structure looks something like this:

`/Documents/.../project/ main directory of project with makefile`
`/Documents/.../project/src here are some sourcefiles and headers`
`/Documents/.../project/src/extended here are some other source and header files`
`/Documents/.../project/src/tools other header and source files`

now lets say I am working on a sourcefile in /tools that includes from extened with #include"/extended/some_header.h" because my makefile is configured to search for files from /src. However when I am trying to compile the file I am working on right now (by using geany compile option which just calls gcc) I cannot compile it obviously because it cannot find /extended/some_header.h in the /src folder. I have tried adding -iquotes/Documents/.../project/src to the gcc call by geany but it doesn't work either.

FlyingTeller
  • 17,638
  • 3
  • 38
  • 53
  • @EugeneSh. IMHO, the linked question is not of very high quality. Do you mind providing another one? (I'm almost sure there is a better dupe, but blame me, i'm feeling too lazy after a long day..) – Sourav Ghosh Jun 15 '15 at 16:31
  • So I guess I'll have to answer this myself.. – Eugene Sh. Jun 15 '15 at 16:36
  • you just need to have gcc knows about your include folder, which can be done by passing `-I` option(upper i). the object files should be compiled one by one and dealt with finally by linker. – Jason Hu Jun 15 '15 at 16:42
  • @HuStmpHrrr In order the linker to deal with objects, they should be generated first. – Eugene Sh. Jun 15 '15 at 16:44
  • @EugeneSh.yeah, that's what i am referring to. – Jason Hu Jun 15 '15 at 16:45

1 Answers1

1

The -I flag tells the gcc compiler where it should look for the header files. Passing the -Idir to the compiler is appending the dir path to the head of the search list, effectively making this path higher priority than the previously (or system) defined paths. As for the source path - there is no such an option for gcc itself. Each source file passed to the compiler has to have it's path (absolute or relative). In order to work it around, a Makefile can be provided, defining a list of files to be compiled.

Eugene Sh.
  • 17,802
  • 8
  • 40
  • 61