[SOLVED]How to include a global architecture header file at the top of each C file
-
wrote on 22 Aug 2013, 14:12 last edited by
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) -
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
-
wrote on 23 Aug 2013, 07:13 last edited by
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\U00000022I 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.htmlBut it does not work.
How do I escape the double qiotes correctly?Øyvind Teig, Trondheim, Norway
-
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
-
wrote on 23 Aug 2013, 07:26 last edited by
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
-
Do you have a space between MY_Q_ARCHITECTURE_H_FILE and = ?
-
wrote on 23 Aug 2013, 07:57 last edited by
Yes, I pasted from yours, which has it. I tried to remove it, same problem.
-
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
-
wrote on 23 Aug 2013, 08:09 last edited by
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 = appCONFIG += console
CONFIG -= app_bundle
CONFIG -= qtSOURCES += 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".....?
-
You are missing almost all of the backslashes. They are all needed to escape the quotes properly
-
wrote on 23 Aug 2013, 08:27 last edited by
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}"
@ -
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 ?
-
wrote on 23 Aug 2013, 09:10 last edited by
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!
-
wrote on 23 Aug 2013, 11:17 last edited by
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/
-
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 :)
-
wrote on 23 Aug 2013, 12:39 last edited by
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
-
wrote on 5 Sept 2013, 13:43 last edited by
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!
-
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 :)
-
wrote on 5 Sept 2013, 14:25 last edited by
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)
-
No button for that... You have to edit your first post and modify the title :)