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,
wxWidgets-3.1.1 gives build errors while 3.0.3 didn't
Re: wxWidgets-3.1.1 gives build errors while 3.0.3 didn't
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.
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!
Re: wxWidgets-3.1.1 gives build errors while 3.0.3 didn't
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:
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.
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_
*/
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.
Re: wxWidgets-3.1.1 gives build errors while 3.0.3 didn't
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:
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.
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_
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.
Re: wxWidgets-3.1.1 gives build errors while 3.0.3 didn't
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.
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.
Re: wxWidgets-3.1.1 gives build errors while 3.0.3 didn't
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.Victory wrote:Any time defs.h happens to get indirectly included in a file more than once this error will be there