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:
Well, I'm almost certain it's because somewhere this happens:
#define DrawText DrawTextA
Why? Because the suffix A
often means "ascii" opposed to the suffix W
which 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.h
is included in your project?
You included windows.h and the DrawText macro replaced DrawText with DrawTextA.
There's not a whole lot you can do about that other than avoid using names that Windows also uses. Not very appealing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With