g++ header search path

This is a discussion on g++ header search path within the Linux Programming forums, part of the Platform Specific Boards category; How can I add a folder and ALL ITS SUBFOLDERS to the "include searching path"? Then if myheader.h is in ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    10

    g++ header search path

    How can I add a folder and ALL ITS SUBFOLDERS to the "include searching path"? Then if myheader.h is in one of these folders, I can use "include <myheader.h>" instead of "include "path/myheader.h" ". I tried g++ -I, but with it I can only specify one folder, I don't know how to make it include all the subfolders.

    I am using a library called spuc. And in its source code, it uses "include <XXX.h>" to include the header files from the library, and these header files are in different subfolders of the library root directory. How should I deal with it?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,500
    > How should I deal with it?
    The normal convention is to use
    #include <path/myheader.h>

    It works well enough for say
    #include <sys/stat.h>
    for example.

    Or you could use a bit of shell script to find all the directories, and make a ridiculously long set of -I parameters out of it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Apr 2011
    Posts
    10
    Quote Originally Posted by Salem View Post
    > How should I deal with it?
    The normal convention is to use
    #include <path/myheader.h>

    It works well enough for say
    #include <sys/stat.h>
    for example.

    Or you could use a bit of shell script to find all the directories, and make a ridiculously long set of -I parameters out of it.
    Thank you! Is there any easy way to add all the sub folders of a folder to the searching path? Because it seems that the source code in that library doesn't follow the normal convention.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,500
    This is crude

    extra_paths=$(find . -type d | sed 's/^/-I/g')

    Then you have
    gcc $extra_paths file.c
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Apr 2011
    Posts
    10
    OK, thank you very much!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. breath first search shortest path
    By iamnew in forum C Programming
    Replies: 3
    Last Post: 06-10-2010, 11:10 AM
  2. breath first search shortest path
    By iamnew in forum C++ Programming
    Replies: 1
    Last Post: 05-01-2010, 01:57 PM
  3. header path & include
    By dontoo in forum C++ Programming
    Replies: 3
    Last Post: 02-19-2010, 04:40 AM
  4. Using the search path
    By DavidG in forum C Programming
    Replies: 8
    Last Post: 05-09-2006, 02:07 AM
  5. Kdevelop compiler search path
    By eth0 in forum Linux Programming
    Replies: 1
    Last Post: 06-05-2004, 11:12 AM

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