Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. [SOLVED]How to include a global architecture header file at the top of each C file
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Installation and Deployment
20 Posts 2 Posters 7.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aclassifier
    wrote on last edited by
    #1

    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:

    @MY_Q_ARCHITECTURE_H_FILE="Q_Architecture.h"@

    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>
    #include MY_Q_ARCHITECTURE_H_FILE@

    Ø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: oyvind.teig@autronicafire.no
    www.autronicafire.no
    www.teigfam.net/oyvind/home/ (also work-related)

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Use the "DEFINES":http://qt-project.org/doc/qt-4.8/qmake-variable-reference.html#defines variable

      Beware, you have to escape the the double quote character

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aclassifier
        wrote on last edited by
        #3

        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="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
        http://qt-project.org/wiki/Strings_and_encodings_in_Qt
        and the advanced page
        http://qt-project.org/doc/qt-4.8/qmake-advanced-usage.html

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

        Øyvind Teig, Trondheim, Norway

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Try something like this:

          @
          ARCHITECTURE_FILE = Q_Architecture.h
          ARCHITECTURE_FILE_STR = '\"$${ARCHITECTURE_FILE}\"'
          DEFINES += MY_Q_ARCHITECTURE_H_FILE ="$${ARCHITECTURE_FILE_STR}"
          @

          There might be a shorter way though

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • A Offline
            A Offline
            aclassifier
            wrote on last edited by
            #5

            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>

            Øyvind

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Do you have a space between MY_Q_ARCHITECTURE_H_FILE and = ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • A Offline
                A Offline
                aclassifier
                wrote on last edited by
                #7

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

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Could you try with a dummy main.cpp ?

                  @
                  #include MY_Q_ARCHITECTURE_H_FILE
                  int main(int argc, char *argv[])
                  {
                  return 0;
                  }
                  @

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

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    aclassifier
                    wrote on last edited by
                    #9

                    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
                    ARCHITECTURE_FILE_STR = '"$${ARCHITECTURE_FILE}"'
                    DEFINES += MY_Q_ARCHITECTURE_H_FILE ="$${ARCHITECTURE_FILE_STR}"

                    HEADERS +=
                    ...

                    @

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

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

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

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        aclassifier
                        wrote on last edited by
                        #11

                        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
                        ARCHITECTURE_FILE_STR = '\"$${ARCHITECTURE_FILE}\"'
                        DEFINES += MY_Q_ARCHITECTURE_H_FILE ="$${ARCHITECTURE_FILE_STR}"
                        @

                        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
                        ARCHITECTURE_FILE_STR = '"$${ARCHITECTURE_FILE}"'
                        DEFINES += MY_Q_ARCHITECTURE_H_FILE ="$${ARCHITECTURE_FILE_STR}"
                        @

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          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 ?

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            aclassifier
                            wrote on last edited by
                            #13

                            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:

                            @
                            D:\Product\AutroKeeper_Sim\Qt\src\build-autrokeeper_Qt_plainC-Desktop_Qt_5_1_0_MinGW_32bit-Release\Makefile.Release
                            @

                            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!

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              aclassifier
                              wrote on last edited by
                              #14

                              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: http://www.teigfam.net/oyvind/home/models/046-sbb-ae-3_6-ii-h0-scale/

                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                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 :)

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                0
                                • A Offline
                                  A Offline
                                  aclassifier
                                  wrote on last edited by
                                  #16

                                  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!

                                  Øyvind

                                  1 Reply Last reply
                                  0
                                  • A Offline
                                    A Offline
                                    aclassifier
                                    wrote on last edited by
                                    #17

                                    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!

                                    1 Reply Last reply
                                    0
                                    • SGaistS Offline
                                      SGaistS Offline
                                      SGaist
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #18

                                      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 :)

                                      Interested in AI ? www.idiap.ch
                                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      1 Reply Last reply
                                      0
                                      • A Offline
                                        A Offline
                                        aclassifier
                                        wrote on last edited by
                                        #19

                                        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)

                                        1 Reply Last reply
                                        0
                                        • SGaistS Offline
                                          SGaistS Offline
                                          SGaist
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #20

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

                                          Interested in AI ? www.idiap.ch
                                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved