Results 1 to 3 of 3

Thread: a C fille including a header file that in turn includes another header file

  1. #1
    Join Date
    Dec 2009
    Beans
    3

    a C fille including a header file that in turn includes another header file

    Ironically I am not a newbie but slightly fuzzy memory. I am trying to punch my way out of a wet paper bag

    Ok ....

    - I have two directories .. say dirA and dirB.

    - dirA contains my C bozo.c file along with an include file (also in dirA) donbass.h. "donbass.h" includes an iinclude file "donesk.h" from dirB.

    - for now I am using command line (bash shell) complilation

    gcc -I. - IdirB -c bozo.c

    The gcc compiler can't find ditrB/"dobass.h" ... Why? (Should be easy peesy")


    BTW I using Ubuntu 18.04 and gcc 7.3.0.

    Vasily

  2. #2
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,490
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: a C fille including a header file that in turn includes another header file

    I am afraid that is all very confusing... which may explain why nobody has tried to help yet.

    - I have two directories .. say dirA and dirB.

    - dirA contains my C bozo.c file along with an include file (also in dirA) donbass.h. "donbass.h" includes an iinclude file "donesk.h" from dirB.

    - for now I am using command line (bash shell) complilation

    gcc -I. - IdirB -c bozo.c
    So far so good... (except for the space between the - and IdirB but I'll assume that's a typo).
    The gcc compiler can't find ditrB/"dobass.h" ... Why?
    You haven't mentioned ditrB before, is it a typo for dirB?
    You haven't mentioned dobass.h before, is it a typo for donbass.h?
    But you said that donbass.h is in dirA, so I'm confused.
    gcc will not (cannot) show the relative directory name for a header it cannot find unless that relative directory is specified in the #include directive e.g.
    Code:
    #include "ditrB/dobass.h"
    If you are doing that, you need -I for the parent directory of ditrB.

    It would help if you could show all relevant #include directives, without typos, and the verbatim compiler output.

    Is dirB a sub-directory of dirA or are you correctly using the relative path? e.g.
    Code:
    gcc -I. -I../path/to/dirB -c bozo.c

  3. #3
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    16,565
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: a C fille including a header file that in turn includes another header file

    Assuming ...
    Code:
    $ tree -d proj
    proj
    ├── bin
    ├── contrib
    ├── doc
    ├── include
    │** ├── dirA
    │** └── dirB
    ├── lib
    ├── share
    └── src
    If it were me, I'd use -I include/ and assume the PWD was the project top and let the makefile determine the real top directory at build time. Then inside my code, the headers would be
    Code:
    #include "dirA/donbass.h" 
    #include "dirB/donesk.h"
    But that's me. Lots of reasons for this, but non-professionals are usually struggling with other coding issues so making a great makefile/Cmakefile that does lots and lots of things automatically isn't normal.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •