I have a small C++ library, compiles fine on Linux (which is my main dev platform). Now I’m trying to build it on a windows machine (XP3) with Mingw, and compiling fails, due to an unexplainable error.
For example, say I have the following method in class AAA, in namespace aaa, declared in file aaa.h:
void AAA::DrawText( foo z );
When compiling file aaa.cpp (that holds of course the methods implementation), I get the following error:
D:\dev\[...]\aaa.cpp:644: error: no 'void aaa::AAA::DrawTextA( foo z )' member function declared in class 'aaa::AAA'
Yep, you got it, no typo there… the compiler misread somehow the functions name, and added a letter to the function identifier !!!
This is absolutely beneath my comprehension. Never had such an issue on Linux. How can mingw / Gcc change an identifier ?
Name mangling ? No, this happens after compiling.
I checked of course the exact command line (I use an IDE): nothing wrong:
mingw32-g++.exe -W -O3 -Wall -I..\include -I"C:\program files\OpenCV2.1\include\opencv" -c D:\dev\...\aaa.cpp -o ..\obj\Release\src\aaa.o
BUT: if I rename the function to, say, DrawTxt(), then everything goes fine (but I can’t do that). This means to me that the identifier is already defined somewhere. Opencv lib ? Grepped the tree, found nothing… And yes, I searched also the current include folder, nothing close.
The other solution that I see is that there is somewhere (?) a macro like:
#define DrawText DrawTextA
that gets activated in some situation.
So my questions are:
- Are there other possibilities for this curious name replacement in my code ? To me, the macro is the only way, if the identifier was already declared elsewhere, it would just throw an error, a compiler can not (well…) abruply change/replace/edit an identifier.
- How can I trackdown the problem ?
Well, I’m almost certain it’s because somewhere this happens:
Why? Because the suffix
Aoften means “ascii” opposed to the suffixWwhich means “wide” (often for unicode). This is a common practice in Windows code to unify ascii and unicode builds with a simple define switch.Also, it seems that the functions exists in the Windows library: http://msdn.microsoft.com/en-us/library/ms901121.aspx. Is
windows.his included in your project?