Quick Compilation Question

This is a discussion on Quick Compilation Question within the C Programming forums, part of the General Programming Boards category; I have a directory structure somewhat like the whats below with many more levels and many more source and header ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    29

    Quick Compilation Question

    I have a directory structure somewhat like the whats below with many more levels and many more source and header files. In all the source files, the headers are included with "String.h" regardless of the current files location (so that would be the include used in say Prime.c). I am currently using the -I option with all of the directories to get it to find the headers. Is there some easier way, for example some recursive -I option that I could just say -I src?

    proj
    ---Makefile
    ---src
    ------Makefile
    ------util
    ---------Makefile
    ---------Threads.c
    ---------Threads.h
    ---------String.c
    ---------String.h
    ------math
    ---------Makefile
    ---------Prime.c
    ---------Prime.h
    ---------Matrix.c
    ---------Matrix.h
    ---bin
    ---lib

    Thanks!
    chacham15

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The -I option to the compiler needs to be exactly the directory that you want to include files from. So you would need to specify -I src/util to include String.h - and there's no getting away from that. You may of course use the outer makefile to set variables that are later on used in the sub-makefiles, so that there's only one place where you set all include directories.

    As a side note: it is bad practice to have header files that are different from standard header files ONLY by the case of the name. In Linux/Unix that works OK, but if you decide to move to Windows, String.h and string.h are the same file - we have had some experiences with going the other way, and sometimes you find code that includes "ABC.H", but the file itself is called "abc.h" - which works fine in Windows, but not in Linux.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    29
    >The -I option to the compiler needs to be exactly the directory that you want to include files from

    Yes, I know. That is why I was hoping that there would be some other option that would tell gcc to recursively scan the directory for the headerfiles.

    >So you would need to specify -I src/util to include String.h - and there's no getting away from that.

    Yes, thats what I am currently doing. But I HATE the long compile lines that say gcc -c -I../../../src/Util -I../../../src/Util/IO -I../../../src/Util/Objs, etc. Is there any way to hide that? Can the headers can be added to the default search path? If so, how? The only problem I have with that is that my other projects might then run into naming conflicts.

    >You may of course use the outer makefile to set variables that are later on used in the sub-makefiles, so that there's only one place where you set all include directories.

    This will still have long compile lines which I hate.

    > As a side note: ...

    Yes, I know, that was just a bad example.

    Thanks,
    chacham15

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    If you don't want to see the lines, use "make -s all".

  5. #5
    Registered User
    Join Date
    Jul 2008
    Posts
    29
    what I want to see is something like:

    gcc -c -I ../../src str.c
    gcc -c -I ../../src bmp.c
    gcc -c -I ../../src hashtable.c
    gcc -c -I ../../src linkedlist.c
    gcc -c -I ../../src threads.c
    gcc -c -I ../../src prime.c
    Warning: line 102....blah blah
    gcc -c -I ../../src matrix.c
    gcc -c -I ../../src regex.c
    gcc -c -I ../../src file.c

    Here its easy to see what is compiling and also easy to see that prime.c has a warning and when the line wraps because the include list is long that becomes difficult (and no, i dont want to make warnings into errors)

    Thanks,
    chacham15

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    gcc's warnings include the filename, so I don't see how not seeing the compile command hurts here.

    Or, there's always redirection (I don't remember whether the output comes out on 1 or 2, but you could try that too).

  7. #7
    Registered User
    Join Date
    Jul 2008
    Posts
    29
    Yes, but they are often hard to find. Compare finding the warning in this set with the one after it.

    gcc -c -I ../../src str.c
    gcc -c -I ../../src bmp.c
    gcc -c -I ../../src hashtable.c
    gcc -c -I ../../src linkedlist.c
    gcc -c -I ../../src threads.c
    gcc -c -I ../../src prime.c
    Warning: line 102....blah blah
    gcc -c -I ../../src matrix.c
    gcc -c -I ../../src regex.c
    gcc -c -I ../../src file.c

    All Im doing is adding the following includes into the command:

    -I ../../src/Util/Whatever -I ../../src/Util/FDGegdwyufsa -I ../../src/Util/DGE34et4g -I ../../src
    /Util/DGE34et4g -I ../../src/Util/Wfgdiancdjkolghnf -I ../../src/Util/Whatever -I ../../src
    /Tab/FDGegdwyufsa -I ../../src/Util/DGE34et4g -I ../../src/Util/Wfgdiancdjkolghnf -I ../../src
    /ComeHither/Whatever -I ../../src/Util/FDGegdwyufsa -I ../../src/Util/DGE34et4g -I ../../src
    /Never/Wfgdiancdjkolghnf

    And this is what you get:

    gcc -c -I ../../src -I ../../src/Util/Whatever -I ../../src/Util/FDGegdwyufsa -I ../../src
    /Util/DGE34et4g -I ../../src/Util/Wfgdiancdjkolghnf -I ../../src/Util/Whatever -I ../../src
    /Tab/FDGegdwyufsa -I ../../src/Util/DGE34et4g -I ../../src/Util/Wfgdiancdjkolghnf -I ../../src
    /ComeHither/Whatever -I ../../src/Util/FDGegdwyufsa -I ../../src/Util/DGE34et4g -I ../../src
    /Never/Wfgdiancdjkolghnf str.c
    gcc -c -I ../../src -I ../../src/Util/Whatever -I ../../src/Util/FDGegdwyufsa -I ../../src
    /Util/DGE34et4g -I ../../src/Util/Wfgdiancdjkolghnf -I ../../src/Util/Whatever -I ../../src
    /Tab/FDGegdwyufsa -I ../../src/Util/DGE34et4g -I ../../src/Util/Wfgdiancdjkolghnf -I ../../src
    /ComeHither/Whatever -I ../../src/Util/FDGegdwyufsa -I ../../src/Util/DGE34et4g -I ../../src
    /Never/Wfgdiancdjkolghnf bmp.c
    gcc -c -I ../../src -I ../../src/Util/Whatever -I ../../src/Util/FDGegdwyufsa -I ../../src
    /Util/DGE34et4g -I ../../src/Util/Wfgdiancdjkolghnf -I ../../src/Util/Whatever -I ../../src
    /Tab/FDGegdwyufsa -I ../../src/Util/DGE34et4g -I ../../src/Util/Wfgdiancdjkolghnf -I ../../src
    /ComeHither/Whatever -I ../../src/Util/FDGegdwyufsa -I ../../src/Util/DGE34et4g -I ../../src
    /Never/Wfgdiancdjkolghnff hashtable.c
    gcc -c -I ../../src -I ../../src/Util/Whatever -I ../../src/Util/FDGegdwyufsa -I ../../src
    /Util/DGE34et4g -I ../../src/Util/Wfgdiancdjkolghnf -I ../../src/Util/Whatever -I ../../src
    /Tab/FDGegdwyufsa -I ../../src/Util/DGE34et4g -I ../../src/Util/Wfgdiancdjkolghnf -I ../../src
    /ComeHither/Whatever -I ../../src/Util/FDGegdwyufsa -I ../../src/Util/DGE34et4g -I ../../src
    /Never/Wfgdiancdjkolghnf linkedlist.c
    gcc -c -I ../../src -I ../../src/Util/Whatever -I ../../src/Util/FDGegdwyufsa -I ../../src
    /Util/DGE34et4g -I ../../src/Util/Wfgdiancdjkolghnf -I ../../src/Util/Whatever -I ../../src
    /Tab/FDGegdwyufsa -I ../../src/Util/DGE34et4g -I ../../src/Util/Wfgdiancdjkolghnf -I ../../src
    /ComeHither/Whatever -I ../../src/Util/FDGegdwyufsa -I ../../src/Util/DGE34et4g -I ../../src
    /Never/Wfgdiancdjkolghnf threads.c
    gcc -c -I ../../src -I ../../src/Util/Whatever -I ../../src/Util/FDGegdwyufsa -I ../../src
    /Util/DGE34et4g -I ../../src/Util/Wfgdiancdjkolghnf -I ../../src/Util/Whatever -I ../../src
    /Tab/FDGegdwyufsa -I ../../src/Util/DGE34et4g -I ../../src/Util/Wfgdiancdjkolghnf -I ../../src
    /ComeHither/Whatever -I ../../src/Util/FDGegdwyufsa -I ../../src/Util/DGE34et4g -I ../../src
    /Never/Wfgdiancdjkolghnf prime.c
    Warning: line 102....blah blah
    gcc -c -I ../../src -I ../../src/Util/Whatever -I ../../src/Util/FDGegdwyufsa -I ../../src
    /Util/DGE34et4g -I ../../src/Util/Wfgdiancdjkolghnf -I ../../src/Util/Whatever -I ../../src
    /Tab/FDGegdwyufsa -I ../../src/Util/DGE34et4g -I ../../src/Util/Wfgdiancdjkolghnf -I ../../src
    /ComeHither/Whatever -I ../../src/Util/FDGegdwyufsa -I ../../src/Util/DGE34et4g -I ../../src
    /Never/Wfgdiancdjkolghnf matrix.c
    gcc -c -I ../../src -I ../../src/Util/Whatever -I ../../src/Util/FDGegdwyufsa -I ../../src
    /Util/DGE34et4g -I ../../src/Util/Wfgdiancdjkolghnf -I ../../src/Util/Whatever -I ../../src
    /Tab/FDGegdwyufsa -I ../../src/Util/DGE34et4g -I ../../src/Util/Wfgdiancdjkolghnf -I ../../src
    /ComeHither/Whatever -I ../../src/Util/FDGegdwyufsa -I ../../src/Util/DGE34et4g -I ../../src
    /Never/Wfgdiancdjkolghnf regex.c
    gcc -c -I ../../src -I ../../src/Util/Whatever -I ../../src/Util/FDGegdwyufsa -I ../../src
    /Util/DGE34et4g -I ../../src/Util/Wfgdiancdjkolghnf -I ../../src/Util/Whatever -I ../../src
    /Tab/FDGegdwyufsa -I ../../src/Util/DGE34et4g -I ../../src/Util/Wfgdiancdjkolghnf -I ../../src
    /ComeHither/Whatever -I ../../src/Util/FDGegdwyufsa -I ../../src/Util/DGE34et4g -I ../../src
    /Never/Wfgdiancdjkolghnf file.c

    Isnt it a lot easier to miss? Especially since the screen will scroll faster!

    Thanks,
    chacham15

  8. #8
    Registered User
    Join Date
    Jul 2008
    Posts
    29
    Oh, I want to see the compile command because that way, Im sure that the file has been recompiled. I dont completely trust that the makefile is without flaws yet.

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    To be honest, if it were me I'd do -I ../../../src, and then do #include "util/Threads.h".

  10. #10
    Registered User
    Join Date
    Jul 2008
    Posts
    29
    Yes, that does work, but then its a pain to move a file..which happens surprisingly often. Any other ideas?

    Thanks,
    chacham15

  11. #11
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Is this one of those thedailywtf-style things where it's just a contest to see how many things we can come up with? Why are we moving things, anyway? If they belong to the project, then once you've figured out where to put them, why wouldn't they stay? (Wouldn't this come under your company's coding convention, somehow?) If they don't belong to the project, then they should be in /usr or /usr/local or /var or somewhere and we wouldn't be having this discussion.

    Edit: And hey, let's go for the gusto: Put symlinks to all the header files in src, and let the OS follow them wherever they may lead.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-27-2005, 12:05 AM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 04:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 05:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 12:04 PM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 06:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21