Results 1 to 20 of 26

Thread: How to force include a header file

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default How to force include a header file

    I have a header file viz., customTypes.h and I need to force include like in Visual Studio.
    In Visual Studio there is a option in settings, called "Force Include" where we select the file, which does this to to the compiler settings -
    Qt Code:
    1. /FI"customTypes.h"
    To copy to clipboard, switch view to plain text mode 

    Now if I'm using that header file from the path, it's linking me to the file while typying #include "customTypes.h", but on compilation, it's giving some type errors.
    Kindly help me how to do this in Qt. Thank you.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to force include a header file

    Assuming you are still using the Microsoft compiler then you do it by arranging for exactly the same command line switch. Something like:
    Qt Code:
    1. QMAKE_CXXFLAGS += /FI"customTypes.h"
    To copy to clipboard, switch view to plain text mode 
    I don't know why this would be useful though.

  3. #3
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to force include a header file

    I'm using MinGW 4.7 and when I do QMAKE_CXXFLAGS += /FI"customTypes.h", it's saying, error: No such file or directory.
    But I've included that header file path in INCLUDEPATH.
    What do I do now? Thank you for the reply.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to force include a header file

    I don't think GCC supports forced include, whatever that is. If you want a file included in your source code then include it there so that people reading your code can learn the file gets included instead of having to analyze crypting compiler invokations.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    rawfool (21st May 2013)

  6. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to force include a header file

    Quote Originally Posted by rawfool View Post
    I'm using MinGW 4.7 and when I do QMAKE_CXXFLAGS += /FI"customTypes.h", it's saying, error: No such file or directory.
    But I've included that header file path in INCLUDEPATH.
    What do I do now? Thank you for the reply.
    It may have helped to have mentioned that you were not using the Microsoft compiler. As it stands at the moment the compiler is probably complaining because there is no file called literally '/FI"customtypes.h"': even cursory inspection of existing command lines or the manual would have highlighted that "/" does not introduce a command line switch to GCC.

    GCC has an equivalent switch that can be found with less than three minutes and the GCC manual:
    Qt Code:
    1. -include "someobscurefilethatisboundtobelost.h"
    To copy to clipboard, switch view to plain text mode 
    Make sure read about where the compiler will be looking for someobscurefilethatisboundtobelost.h.

    The correct approach is to fix your source code, not to try and fudge it with obscure compiler options.

  7. The following user says thank you to ChrisW67 for this useful post:

    rawfool (21st May 2013)

  8. #6
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to force include a header file

    My customTypes.h file is in C:/svn/trunk/vtd-xml, how do I force include ?
    I tried each of the following ways in my .pro file, but it's giving error
    Qt Code:
    1. -include "customTypes.h"
    2. INCLUDEPATH += <some/path> \
    3. C:/svn/trunk/vtd-xml
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. -include "C:/svn/trunk/vtd-xml/customTypes.h"
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. // Without quotes
    2. -include C:/svn/trunk/vtd-xml/customTypes.h
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. -include -I"C:/svn/trunk/vtd-xml/customTypes.h"
    To copy to clipboard, switch view to plain text mode 
    All the attempts giving -
    Qt Code:
    1. Extra characters after test expression.
    2. [Makefile] Error 3
    To copy to clipboard, switch view to plain text mode 

  9. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to force include a header file

    QMAKE_CXXFLAGS += "-include ..."
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. The following user says thank you to wysota for this useful post:

    rawfool (21st May 2013)

  11. #8
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to force include a header file

    Thank you Wysota for the reply.
    I did that it's almost working, still I need some more clarifications regd., this.
    The file C:/svn/trunk/vtd-xml/customTypes.h is being used by any other files and those needs to be specified. I tried including all those files below mentioned way. But no luck. kindly help me.
    Qt Code:
    1. QMAKE_CXXFLAGS += "-include C:/svn/trunk/vtd-xml/customTypes.h C:/svn/trunk/vtd-xml/arrayList.h C:/svn/trunk/vtd-xml/autoPilot.h C:/svn/trunk/vtd-xml/binaryExpr.h C:/svn/trunk/vtd-xml/bookMark.h C:/svn/trunk/vtd-xml/cachedExpr.h ...(many other files separated by space)"
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. error: fatal error: cannot specify -o with -c, -S or -E with multiple files
    To copy to clipboard, switch view to plain text mode 

    The files other than customTypes.h need not be force included, but just included because, customTypes.h file is being used by all the other files (and the files are in that specified directory).
    Last edited by rawfool; 21st May 2013 at 09:13.

  12. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to force include a header file

    This is not a GCC usage kindergarden. Read the manual. Or better yet fix your code to avoid using forced includes.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #10
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to force include a header file

    The GCC "-include" option, as the manual clearly indicates, takes a single file name as an argument.

    If the customTypes.h is already "being used by any other files" then I fail to see why a forced included is required. If the "any other files" contained the line:
    Qt Code:
    1. #include "customTypes.h"
    To copy to clipboard, switch view to plain text mode 
    you would not have the problem you have made for yourself.

  14. #11
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to force include a header file

    I'm force including customTypes.h file which is part of other process developed using Visual C++. Also the files that are including customTypes.h file are part of that process.
    I'm trying to load a DLL that parses a huge xml file. That parser DLL is created by other team and they use Visual C++ for development. So that's the reason I'm left with only option of force including the required files for using required DLL APIs.
    Thank you.

  15. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to force include a header file

    That's not true. If you physically have the file there and its presence is mandatory for the compilation to work then you can as well include the file directly in your files. Using your currrent approach only obscures your source code making it more error prone and more difficult to manage. If the other team provides a library you have to use, then just use it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Must I include each widget header with qt5?
    By aguayro in forum Newbie
    Replies: 8
    Last Post: 27th December 2012, 15:53
  2. Replies: 5
    Last Post: 16th January 2011, 15:19
  3. The header file 'mainwindow.h' doesn't include <QObject>.
    By nhs_0702 in forum Qt Programming
    Replies: 5
    Last Post: 14th May 2010, 17:02
  4. compile to arm+include header
    By nataly in forum Qt Programming
    Replies: 1
    Last Post: 8th November 2009, 12:59
  5. unable to include header file
    By sonia in forum Qt Programming
    Replies: 1
    Last Post: 10th July 2007, 08:56

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.