[SOLVED] different method signatures for mingw and visual c
-
wrote on 30 Aug 2013, 14:40 last edited by
I am writing code in QT that can be compiled with both MinGW and Visual C compiler. I am using define like this:
I have defined VISUAL_STUDIO In my project file as follows:
@
QMAKE_CFLAGS_DEBUG += -O2 VISUAL_STUDIO
QMAKE_CFLAGS += -O2 -DVISUAL_STUDIO
@I get multiple definition error for the following code
@
#ifdef VISUAL_STUDIO
int FUNCA(
#else
static inline int FUNCA(
#endif
Pkt_t *pkt
)
@Can anybody help me with this or any idea to do it in different was will be appreciated?
-
Hi,
You are missing a -D for your QMAKE_CFLAGS_DEBUG
You could also simply use DEFINES += VISUAL_STUDIO
Hope it helps
PS: are you sure you want/need two set of function signatures ?
-
wrote on 30 Aug 2013, 15:27 last edited by
Thanks for your reply,
I tried both of your suggestions, adding missing -D in flags and using DEFINES one after the other...
It didn't help either way. I still get multiple definition error
Where am I doing something wrong? -
Without more information it becomes crystal ball guessing. You could be linking multiple libraries that provides the same function
-
wrote on 30 Aug 2013, 21:51 last edited by
The function definition is likely to be in a header file that is being included in several different cpp files... but I am just guessing.
-
wrote on 31 Aug 2013, 07:39 last edited by
Thanks for your reply.
I only get this error after adding these two different function definitions.There is no error with @ static inline int FUNCA( Pkt_t *pkt )@
I get multiple definition errors with this:
@
#ifdef VISUAL_STUDIO
int FUNCA(
#else
static inline int FUNCA(
#endif
Pkt_t *pkt
)
@There is no other change in the program.
-
Maybe you're including this header from two places only one of which sees the define so you get bot declarations?
But why are you using your own define in the first place? There's a Qt one for this: Q_CC_MSVC and Q_CC_MINGW, or their underlying counterparts _MSC_VER and __MINGW32__. Try with one of those.
-
wrote on 1 Sept 2013, 10:29 last edited by
Thanks, QT defined worked for me.
What is wrong with custom defines? Why are these giving errors?
-
There's nothing wrong with user defines. There's probably something wrong with how you used them :) For example when you use one header in two statically linked libraries and the define differs in them.
But without seeing the whole setup you got it's as good as guessing. -
wrote on 2 Sept 2013, 08:52 last edited by
Following is my setup:
I define the DEFINES in QT project file like this;
@
DEFINES += VISUAL_STUDIO
@Use this define in my header file
@#ifdef VISUAL_STUDIO
int FUNCA(
#else
static inline int FUNCA(
#endif
Pkt_t *pkt
)
@Use this header file in one C file and in different header files.
-
What Chris Kawa meant is:
Do you also make this define when using your header in other projects ? -
wrote on 2 Sept 2013, 12:11 last edited by
No, I am using this define only in this project.
-
But your header is used in other projects ?
-
wrote on 2 Sept 2013, 14:05 last edited by
no. The header file is only used in this project.
-
Project using sub-projects ?
-
wrote on 3 Sept 2013, 02:03 last edited by
Do a complete clean build, i.e. delete all the intermediate files. If the error persists it would really help if you posted the full command that generated the error message and the full error message that followed verbatim (copy and paste, do not paraphrase). Usually the compiler error message tells you exactly where it thinks the earlier declaration occurred.
It would also help if you posted the few lines immediately following your ifdef-ed section. Since there is no semicolon of line 7 it is entirely possible that you are providing the function implementation rather than just declaring the function in the header: including that twice anywhere in your program will, as already pointed out, lead to this sort of error.
1/16