Thread: header path issues

  1. #1
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,593

    header path issues

    K, so I tried to make gcc generate absolute paths by defining a variable for where my headers are located and attempted to concatenate it like this:

    Code:
    gcc ... -D INC_X="\"./include/\"" ...
    
    #include INC_X "x/..."
    But that failed with
    Code:
    include/x/...:L:C: warning: extra tokens at end of #include directive
        C | #include INC_X "x/..."
          |                ^~~~~~~~~~~~~~~~~~~~~
    <command-line>: fatal error: ./include/: No such file or directory
    Anyone have any ideas how to do this cross compiler wise?

  2. #2
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,593
    Okay, so I had an idea to work around the issue since macros are at least allowed:

    Code:
    #define INC_3X_H(INC) #INC
    #define INC_2X_H(DIR,INC) INC_3X_H(DIR##INC)
    #define INC_1X_H(DIR,INC) INC_2X_H(DIR,INC)
    #define INC_X_H(INC) INC_1X_H(INC_PAW,INC)
    #define MSG_2X_H(MSG) _Pragma(#MSG)
    #define MSG_1X_H(MSG) MSG_2X_H(GCC warning #MSG)
    #define MSG_X_H(MSG) MSG_1X_H(MSG)
    
    MSG_X_H(INC_X_H(x/...))
    #include INC_X_H(x/...)
    Currently failing to get output from the pragma but I'll leave that aside for a moment while I address the error that did pop up:
    Code:
    include/x/...:L:C: error: #include expects "FILENAME" or <FILENAME>
       L | #include INC_X_H(x/...)
    Edit: Noticed I made a typo, with that fixed and double checking the supported pragma directives for GCC I got this output (irrelevant stuff edited down to just X and x/...):

    Code:
    cc ... -D INC_X="./include/" ...
    In file included from include/x/...:4,
                     from include/x/...:4,
                     from .../libx/...:1:
    <command-line>: error: pasting "/" and "x" does not give a valid preprocessing token
    include/x/...:L:C: note: in definition of macro ‘INC_2X_H’
        L | #define INC_2X_H(DIR,INC) INC_3X_H(DIR##INC)
          |                                                                    ^~~
    include/x/...:L:C: note: in expansion of macro ‘INC_1X_H’
        L | #define INC_X_H(INC) INC_1X_H(INC_X,INC)
          |                                      ^~~~~~~~~~~~~~~~~~~~~~~~
    include/x/...:L:C: note: in expansion of macro ‘INC_X’
        L | #define INC_X_H(INC) INC_1X_H(INC_X,INC)
          |                                                               ^~~~~~~
    include/x/...:L:C: note: in expansion of macro ‘INC_X_H’
        L | MSG_X_H(INC_X_H(x/...))
          |                         ^~~~~~~~~~~~~~~~~~~~~~~
    include/x/...:L:C: warning: Trying: "./include/x/..."
        L | MSG_X_H(INC_X_H(x/...))
          |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    <command-line>: error: pasting "/" and "x" does not give a valid preprocessing token
    include/x/...:L:C: note: in definition of macro ‘INC_2X_H’
        L | #define INC_2X_H(DIR,INC) INC_3X_H(DIR##INC)
          |                                                                    ^~~
    include/x/...:L:C: note: in expansion of macro ‘INC_1X_H’
        L | #define INC_X_H(INC) INC_1X_H(INC_X,INC)
          |                                      ^~~~~~~~~~~~~~~~~~~~~~~~
    include/x/...:L:C: note: in expansion of macro ‘INC_X’
        L | #define INC_X_H(INC) INC_1X_H(INC_X,INC)
          |                                                               ^~~~~~~
    include/x/...:L:C: note: in expansion of macro ‘INC_X_H’
        L | #include INC_X_H(x/...)
          |          ^~~~~~~~~~~~~~~~~~~~~~~
    include/x/...:L:C: fatal error: ./include/x/...: No such file or directory
        L | #include INC_X_H(x/...)
          | ^
    compilation terminated.
    ...

  3. #3
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,593
    Never mind, found my solution:
    Code:
    #define INC_2X_H(INC) #INC
    #define INC_1X_H(DIR,INC) INC_2X_H(DIR/INC)
    #define INC_X_H(INC) INC_1X_H(INC_X,INC)
    
    #include INC_X_H(...)
    I'm using the header defines for it because I want the macro to be usable even without having included anything yet, the next experiment involves trying to declare those same macros via command line thereby removing the need to define them directly in code, yes it means extra defines are needed but guarantee's error messages that spit out absolute paths instead of half useful messages that only contain relative paths (which are unclickable in some cirumstances)

    Edit: This is what has worked for me just now at compiler launch:
    Code:
    cc ... -D "SUBINC(INC)=#INC" -D "INCLUDE(DIR,INC)=SUBINC(DIR/INC)" -D "INC_X(INC)=INCLUDE(${PWD}/include,INC)" ...
    I don't have windows or Visual C++ etc to try their variant of:
    Code:
    cc ... /D "SUBINC(INC)=#INC" /D "INCLUDE(DIR,INC)=SUBINC(DIR/INC)" /D "INC_X(INC)=INCLUDE(%CD%/include,INC)" ...
    So if someone who does encounters an issue please let me know along with any fixes you applied to get it working (assuming you did get it working)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Where to include path of header files in Visual Studio
    By emmagood in forum C++ Programming
    Replies: 15
    Last Post: 05-16-2012, 11:53 PM
  2. g++ header search path
    By talentspsp in forum Linux Programming
    Replies: 4
    Last Post: 04-18-2011, 11:38 AM
  3. header path & include
    By dontoo in forum C++ Programming
    Replies: 3
    Last Post: 02-19-2010, 05:40 AM
  4. Header /file module issues
    By rogster001 in forum C++ Programming
    Replies: 7
    Last Post: 10-21-2009, 06:48 AM
  5. DirectSound header issues
    By dxfoo in forum C++ Programming
    Replies: 0
    Last Post: 03-19-2006, 07:16 PM

Tags for this Thread