wxWidgets-3.1.1 gives build errors while 3.0.3 didn't

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
Victory
Earned some good credits
Earned some good credits
Posts: 115
Joined: Fri Mar 19, 2010 1:20 am

wxWidgets-3.1.1 gives build errors while 3.0.3 didn't

Post by Victory »

I just tried updating our code to use wxWidgets-3.1.1 and I am now getting a few occurrences of the following error:

1>c:\blahblah\wxwidgets\wxwidgets-3.1.1\include\wx\msw\winundef.h(246): error C2084: function 'int DrawText(HDC,LPCWSTR,int,LPRECT,UINT)' already has a body
1> c:\blahblah\wxwidgets\wxwidgets-3.1.1\include\wx\msw\winundef.h(245) : see previous definition of 'DrawText'

Our code has been building fine with wxWidgets-3.0.3.

Any idea about the cause/fix?

I am building with Visual Studio 2012 on Windows 10.

Thanks,
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxWidgets-3.1.1 gives build errors while 3.0.3 didn't

Post by doublemax »

First of all: Make sure you make a clean rebuild of the libraries and that you're not using any headers from the old wx version.

The error message is pretty clear, but not very helpful on its own. Check the order of include files in the source file that creates the error.

Generally you should include all wx related headers first, then any other Windows or third party header files.
Use the source, Luke!
Victory
Earned some good credits
Earned some good credits
Posts: 115
Joined: Fri Mar 19, 2010 1:20 am

Re: wxWidgets-3.1.1 gives build errors while 3.0.3 didn't

Post by Victory »

I looked a bit into what is causing the build errors. The problem seems to be related to winundef.h. Unlike other header files, this header file has its include guard commented out. This is what the code at the top of that file says:

Code: Select all

/* THIS SHOULD NOT BE USED since you might include it once e.g. in window.h,
 * then again _AFTER_ you've included windows.h, in which case it won't work
 * a 2nd time -- JACS
#ifndef _WX_WINUNDEF_H_
#define _WX_WINUNDEF_H_
 */
As a result, this header file ends up getting included multiple times which means the functions contained in the header (e.g., DrawText in the post above) get added multiple times, causing the "already has a body" error.

Now, the question is why I get this build error only with wxWidgets-3.1.1 and not with earlier versions such as wxWidgets-3.0.3. Not sure yet what change in wxWidgets-3.1.1 might be triggering this.
I am still struggling with this one. Reordering of the files as you suggested is very messy and hasn't solved it yet for me.
Thanks.
Victory
Earned some good credits
Earned some good credits
Posts: 115
Joined: Fri Mar 19, 2010 1:20 am

Re: wxWidgets-3.1.1 gives build errors while 3.0.3 didn't

Post by Victory »

After investigating some more, I found the change in wxWidgets-3.1.1 that seems to be at the heart of this. In the 3.1.1 version, the following include has been added near the top of the file wx\defs.h:

Code: Select all

#ifdef __cplusplus
    /*
        Test for _WINDOWS_, used as header guard by windows.h itself, not our
        own __WINDOWS__, which is not defined yet.
     */
#   ifdef _WINDOWS_
#       include "wx/msw/winundef.h"
#   endif /* WIN32 */
#endif /* __cplusplus */


#ifndef _WX_DEFS_H_
#define _WX_DEFS_H_
Note that the including of winundef.h is outside of the _WX_DEFS_H_ include guard. In 3.0.3 version, the including of winundef.h in defs.h is well inside the #ifndef _WX_DEFS_H_ include guard.

Now that the inclusion of winundef.h has been moved out of the _WX_DEFS_H_ include guard in 3.1.1, and since winundef.h doesn't have its own include guard, winundef.h ends up getting included multiple times causing the "already has a body" build error. Any time defs.h happens to get indirectly included in a file more than once this error will be there.

Moving the inclusion of winundef.h to be inside the _WX_DEFS_H_ include guard, as it used to be in wxWidgets-3.0.3, fixed all the build errors I was getting.
IMHO, this is an issue that should be fixed in the wxWidgets distribution itself.


Thanks.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxWidgets-3.1.1 gives build errors while 3.0.3 didn't

Post by ONEEYEMAN »

Hi,
This forum is designed by wx users and it is created for wx users.
There is no core wx-dev here, other than tierra, who is actually an infrastructure person.

If you are convinced that this is the problem and switching the include files won't help, send an e-mail to the wx-dev ML (you will need to register first) explaining you situation and try to give a reproducible case with the minimal sample (provided in wxWidgets/samples/minimal).

Thank you.
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: wxWidgets-3.1.1 gives build errors while 3.0.3 didn't

Post by catalin »

Victory wrote:Any time defs.h happens to get indirectly included in a file more than once this error will be there
Do you have a smallest possible piece of code that makes that happen? Remember that you are not supposed to include any of those headers (not only defs.h) directly in your code.
Post Reply