[SOLVED] different method signatures for mingw and visual c
-
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 ?
-
Without more information it becomes crystal ball guessing. You could be linking multiple libraries that provides the same function
-
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.
-
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. -
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 ? -
But your header is used in other projects ?
-
Project using sub-projects ?
-
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.