Where do c source and header files live? - Unix

This is a discussion on Where do c source and header files live? - Unix ; Hi guys I want to be able to look at the header files that my system and C compiler are using. I'm running mac os x panther. When I poked around the development folders a bit, I was surprised to ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Where do c source and header files live?

  1. Where do c source and header files live?

    Hi guys

    I want to be able to look at the header files that my system and C
    compiler are using. I'm running mac os x panther. When I poked
    around the development folders a bit, I was surprised to see a ton of
    similarly named folders and files, and various versions of of files
    etc. How does one make sense of this? When I include a system h file
    in my program, is there a way to find out exactly what file is being
    referenced? I'm a bit used to java where you can drill right into the
    core source code from an IDE.

    I guess another similar question i had is this: in our programs we
    use h files as interfaces to the actual implementation in c files.
    Are system files the same? Do h files like reference an
    actual c file? Can we look int it and see how it was implemented?
    that would be neat. Or, is it the case that you need h files to
    interface to library files as well. thanks for any clarification.

  2. Re: Where do c source and header files live?

    On Aug 12, 9:15*am, darren wrote:
    > When I include a system h file
    > in my program, is there a way to find out exactly what file is being
    > referenced?


    On most unix-like systems, header files live in /usr/include. You will
    find stdio.h, stdlib.h etc. there. If you include , the
    file /usr/include/sys/select.h will be used.

    The header files define preprocessor macro's and function prototypes.
    In stdio.h, for example, the function printf is declared, but the
    implementation is not given. The implementation of printf is part of
    libc, a library at /usr/lib/libc.so. The source of the libc library is
    probably not on your system already, but you may be able to download
    it.

  3. Re: Where do c source and header files live?

    >I want to be able to look at the header files that my system and C
    >compiler are using. I'm running mac os x panther. When I poked
    >around the development folders a bit, I was surprised to see a ton of
    >similarly named folders and files, and various versions of of files
    >etc. How does one make sense of this? When I include a system h file
    >in my program, is there a way to find out exactly what file is being
    >referenced? I'm a bit used to java where you can drill right into the
    >core source code from an IDE.


    If you run "cc -E sourcefile.c | more", and note the lines beginning
    with # and containing a line number and file name, these are the
    files referenced by the preprocessor in building the preprocessed
    code to compile. With gcc there is also "gcc -M sourcefile.c",
    which will output a make(1) dependency line listing all of the include
    files used.

    Common UNIX locations for system include files are in /usr/include
    and subdirectories of that directory. Common UNIX locations for
    libraries are in /lib or /usr/lib.

    >I guess another similar question i had is this: in our programs we
    >use h files as interfaces to the actual implementation in c files.
    >Are system files the same?


    For a non-open-source system the .c files may not be present.
    The compiled code will be present in libraries.

    >Do h files like reference an
    >actual c file?


    I have not heard of include files actually naming .c files other
    than in comments. The functions referred to in may
    be defined in dozens or hundreds of .c files which may or may
    not be present on the system. (Example: on FreeBSD libc.a
    contains 998 object files from 998 compilations or assemblies.)

    >Can we look int it and see how it was implemented?


    On an open-source system that has the source code installed, yes.

    >that would be neat. Or, is it the case that you need h files to
    >interface to library files as well. thanks for any clarification.


    If you wish to use a particular system function in your program,
    you should:

    (1) include the proper header file that includes a prototype of
    the function (and related definitions like structures and types
    needed to use it).

    (2) link with the library containing the code for the function.
    Including the .h file will *NOT* do this for you. Note that in
    programs being developed, you can use the .h file to compile code
    (but not run it) even though the corresponding .c file(s) HAVEN'T
    BEEN WRITTEN YET. The interface can be designed before the
    implementation is complete, or even really started.


  4. Re: Where do c source and header files live?

    darren writes:
    >I want to be able to look at the header files that my system and C
    >compiler are using. I'm running mac os x panther. When I poked
    >around the development folders a bit, I was surprised to see a ton of
    >similarly named folders and files, and various versions of of files
    >etc. How does one make sense of this? When I include a system h file
    >in my program, is there a way to find out exactly what file is being
    >referenced? I'm a bit used to java where you can drill right into the
    >core source code from an IDE.


    Darwin is a bit confusing, they do seem to bundle the same versions of
    files all over the place. In general, you'll be pulling from
    /usr/include and /usr/lib, but for the full path specs, run

    gcc -dumpspecs

    to get the whole "spec" file as to where GCC will look to get files.

    Many of the files in /Developer are reference files, and are the same
    as what you find in the /usr/include area. Also, once you get
    Frameworks involved, you'll find them in many more places all over..

    xcode is your friend, and will keep it all straight for you. You
    should probably be able to drill down to the header files in use
    within xcode as well.

    >I guess another similar question i had is this: in our programs we
    >use h files as interfaces to the actual implementation in c files.
    >Are system files the same? Do h files like reference an
    >actual c file? Can we look int it and see how it was implemented?
    >that would be neat. Or, is it the case that you need h files to
    >interface to library files as well. thanks for any clarification.


    Yes, in general, but you'll find such a standard header as stdio.h,
    that most of it is dictated by POSIX and other standards that they
    conform to rather than having internal implementations detail.
    Its not like they generally have a private stdio.h file and a public one,
    but some of this stuff is so well defined by history that they can't
    do much else but what is there now.

+ Reply to Thread