Important: Please read the Qt Code of Conduct -

[SOLVED]How to include a global architecture header file at the top of each C file

  • I am making a desktop version of a large embedded project, written in C. It's meant for better unit tests without having to download on target.

    For the small 8-bit target we use an IAR compiler. To do this, I have added the following line in the IAR project description:


    This way I am able to switch target header file without changing code.
    Now every C file starts like this:

    @#include MY_Q_ARCHITECTURE_H_FILE // Don't want to change in 100+ files! @

    HOW DO I DO THIS IN Qt? It's a plain C with qmake project.

    I have tried several syntaxes both in the .pro file and in the Project Additional Arguments, but failed.
    It would complain like this:

    @..\scheduler\S_ChanSched.c:2:10: error: #include expects "FILENAME" or <FILENAME>

    Øyvind Teig
    Senior development engineer, M.Sc.

    Autronica Fire and Security AS
    UTC CCS EMEA Fire & Security Operations
    Phone: + 47 73 58 24 68 / Mobile +47 959 61 506
    E-mail: (also work-related)

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Use the "DEFINES": variable

    Beware, you have to escape the the double quote character

  • SGaits, thanks.

    Sorry, I forgot to say that I did read that page first, and tried virtually "everything".

    Here is a list of things that does not work, and that I have tried in the .pro file:
    DEFINES += MY_Q_ARCHITECTURE_H_FILE="Q_Architecture.h"
    DEFINES += MY_Q_ARCHITECTURE_H_FILE=""Q_Architecture.h""
    DEFINES += MY_Q_ARCHITECTURE_H_FILE="Q_Architecture.h"
    DEFINES += MY_Q_ARCHITECTURE_H_FILE=\x22Q_Architecture.h\x22
    DEFINES += MY_Q_ARCHITECTURE_H_FILE=\u0022Q_Architecture.h\u0022
    DEFINES += MY_Q_ARCHITECTURE_H_FILE=\U00000022Q_Architecture.h\U00000022

    I have read the escape page
    and the advanced page

    But it does not work.
    How do I escape the double qiotes correctly?

    Øyvind Teig, Trondheim, Norway

  • Lifetime Qt Champion

    Try something like this:

    ARCHITECTURE_FILE = Q_Architecture.h

    There might be a shorter way though

  • No.. it seems like qmake parses it ok, but compiler still says

    D:\Product\AutroKeeper_Sim\Qt\src\autrokeeper\P_IoAd.c:2: error: #include expects "FILENAME" or <FILENAME>


  • Lifetime Qt Champion

    Do you have a space between MY_Q_ARCHITECTURE_H_FILE and = ?

  • Yes, I pasted from yours, which has it. I tried to remove it, same problem.

  • Lifetime Qt Champion

    Could you try with a dummy main.cpp ?

    int main(int argc, char *argv[])
    return 0;

    I just tested it (with qstring.h) and it works

  • Have now tried that code in my main.c (not cpp). Same problem:

    D:\Product\AutroKeeper_Sim\Qt\src\autrokeeper_Qt_plainC\main.c:2: error: #include expects "FILENAME" or <FILENAME>

    I have compiled along the line. So, maybe there's a problem with my make file? Here is an excerpt:

    TEMPLATE = app

    CONFIG += console
    CONFIG -= app_bundle
    CONFIG -= qt

    SOURCES += main.c
    INCLUDEPATH += ...

    ARCHITECTURE_FILE = Q_Architecture.h

    HEADERS +=


    By the way, what's this "with qstring.h".....?

  • Lifetime Qt Champion

    You are missing almost all of the backslashes. They are all needed to escape the quotes properly

  • Still does not work. Hmm.. And I now use exactly this (which might come out wrong in the mail, see bottom):

    ARCHITECTURE_FILE = Q_Architecture.h

    So what's this "qstring.h" stuff? Didn't think qmake accepted any external defs? Hmm..

    By the way, the Qt forum should fix their forum-to-mail sw. The extra backslashes got lost there. In my Outlook on XP it looks like this, from which I innocently pasted:-)

    ARCHITECTURE_FILE = Q_Architecture.h

  • Lifetime Qt Champion

    I meant I use qstring.h rather than Q_Architecture.h for my test to ensure that everything was working.

    After the changes, did you rebuild the project from scratch ?

  • Well no, not really. If I do, I now get

    @<command-line>:0: error: macro names must be identifiers
    File not found: <command-line>@

    Rebuilding I get
    The Makefile.Release has changed outside Qt Creator. Do you want to reload it?

    Show details then shows:


    Does this have any significance? My .pro file is the one that's in the project in the Creator. I do see that it's used, since I am able to get parse errors.

    Not blank any more, but not in goal either. Thanks for your patience!

  • I think I'm giving this up! I've also tried to use the environment.

    I have a feeling my first encounter with Qt hit the wall.

    I'll introduce another indirection and do a non-fuzz include at the top of each file, to a primary include file that again includes my actual architecture file.

    Is it too early to give up? I've also asked people here.

    Samuel, since you are in CH and since it's Friday:

  • Lifetime Qt Champion

    Very strange... I wonder If it's mingw related but I doubt...

    Did you try both from QtCreator and command line ? (meaning deleting the content of the shadow build directory)

    Nice link :)

  • I,ve tried both editing in the .pro file and in the qmake additional arguments, and tried read from the envirnoment ("all" permutations), and have tried to clean all and not, and I'm still at square one. That might answer your question..

    Even if I do make an extra indirection file, which of course will work - it would be interesting to be informed of a solution to this thread.

    I will be out of reach until 29th. Thank you!


  • I ended up using an indirect file instead of trying to define that file in the IDE. Now I branch off in that file to different architecture files.

    GCC did not seem to allow what IAR did, which allows file name including quotes in the IDE, to pass over to user code, quotes and all.

    Thank you!

  • Lifetime Qt Champion

    You welcome !

    Since you got it working, please update the thread's title to solved so other forum users may know a solution has been found :)

  • Guess, what, I looked for it before I sent the last message, but even when you have told me there is one I cannot see any such button.. (Safari on XP)

  • Lifetime Qt Champion

    No button for that... You have to edit your first post and modify the title :)

Log in to reply