Thread: compiling and finding the source

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    69

    compiling and finding the source

    Dumb question, but when you include a header file in a C program, how does the compiler/program know where to find the source file?

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    1. Config files, or the registry
    2. Hard coded into the compiler
    3. User defined (or environment variables).

    Usually, the compiler will have a list of places it will go through in order to find the header. For example,
    1. Where you tell it to look
    2. /usr/include
    3. /path/to/my/program

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    69
    By source file, I meant the *.c file. If I specify foo.h, does the compiler/program look for foo.c in the same location as foo.h?

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    if you use "" - then compiler start from the current folder, then it goes all the include path
    then you use <> - it skips the current folder and starts with the include path scanning directly
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling Anagramarama
    By biggins in forum C Programming
    Replies: 2
    Last Post: 01-18-2007, 05:35 PM
  2. Help on compiling code
    By mattyp1977 in forum C++ Programming
    Replies: 4
    Last Post: 03-26-2006, 05:07 PM
  3. need help finding problems
    By kwm32 in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2004, 05:49 PM
  4. Finding out a Parse error
    By Ziionyx in forum C++ Programming
    Replies: 2
    Last Post: 04-01-2003, 01:05 PM