Moving to Visual Studio 2019
Moving to Visual Studio 2019
Hello everybody !
I recently moved to Visual Studio 2019 and I tried to rebuild a C++ program that worked perfectly with Visual 2017.
I have two C2084 fatal errors, both of them as follows :
D:\C++\wxWidgets\include\wx\msw\winundef.h(238): error C2084: function 'int DrawText(HDC,LPCWSTR,int,LPRECT,UINT)' already has a body
Obviously, it has Something to deal with the fact that I have several several headers calling for wx.h :
#include <wx/wx.h>
or :
#include <wx/wx.h>
#include <wx/msw/winundef.h>
I tried to remove most of them but in that case I have thousands of errors during the build !
I am using the wxWidgets 3.0.4 version that I have rebuilt with Visual 2019.
I can't figure out what's happening. I still have 2017 installed and it works without any errors !
Can you help me ?
Thanks in advance
Hervé
I recently moved to Visual Studio 2019 and I tried to rebuild a C++ program that worked perfectly with Visual 2017.
I have two C2084 fatal errors, both of them as follows :
D:\C++\wxWidgets\include\wx\msw\winundef.h(238): error C2084: function 'int DrawText(HDC,LPCWSTR,int,LPRECT,UINT)' already has a body
Obviously, it has Something to deal with the fact that I have several several headers calling for wx.h :
#include <wx/wx.h>
or :
#include <wx/wx.h>
#include <wx/msw/winundef.h>
I tried to remove most of them but in that case I have thousands of errors during the build !
I am using the wxWidgets 3.0.4 version that I have rebuilt with Visual 2019.
I can't figure out what's happening. I still have 2017 installed and it works without any errors !
Can you help me ?
Thanks in advance
Hervé
Re: Moving to Visual Studio 2019
Just to make sure the issue is within wxWidgets: can you build bundled drawing sample? Make 100% sure you cleared anything that may be left over from MSVC 2017 build, no matter how compatible the two compilers are supposed to be.
I myself am too old to attempt using the very first release of a new version of agile-developed MSVC, so I have no experience with it yet.
If there is an issue with wxWidgets, you need to report it to wxTracker. However, I do not know chances of possibly fixing MSVC 2019 issue in 3.0 branch... If you do report it, please attach detailed information about build, in particular: how you built wxWidgets, MSVC settings regarding conformance mode and platform toolset, platform SDK version...
I myself am too old to attempt using the very first release of a new version of agile-developed MSVC, so I have no experience with it yet.
If there is an issue with wxWidgets, you need to report it to wxTracker. However, I do not know chances of possibly fixing MSVC 2019 issue in 3.0 branch... If you do report it, please attach detailed information about build, in particular: how you built wxWidgets, MSVC settings regarding conformance mode and platform toolset, platform SDK version...
Re: Moving to Visual Studio 2019
I built the drawing sample and it works perfectly.
As for my program, I have created a new directory and copied just the header and source files.
Thanks for the quick reply.
As for my program, I have created a new directory and copied just the header and source files.
Thanks for the quick reply.
Re: Moving to Visual Studio 2019
Actually, I Don't think there is any issue with wxWidgets. I'm pretty sure it has Something to deal with my multiple declarations of wx.h and winundef.h. I just don't understand why it's no longer working and how to avoid these multiple déclarations.
Cheers
Cheers
Re: Moving to Visual Studio 2019
#includeing a header file multiple times should not matter, as all wxWidgets header files have guards against it.
Assuming you really need to #include <wx/msw/winundef.h>, make sure this statement is after all wxWidgets header includes and after #include <windows.h>. But why would this break with new MSVC?
Did the errors manifested only after moving your header and source files into a new folder? If yes, and assuming you created a new project; make sure that you have all the MSVS settings as well as preprocessor defines (be it _UNICODE or wxWidgets-specific ones) same as in the original project.
Assuming you really need to #include <wx/msw/winundef.h>, make sure this statement is after all wxWidgets header includes and after #include <windows.h>. But why would this break with new MSVC?
Did the errors manifested only after moving your header and source files into a new folder? If yes, and assuming you created a new project; make sure that you have all the MSVS settings as well as preprocessor defines (be it _UNICODE or wxWidgets-specific ones) same as in the original project.
Re: Moving to Visual Studio 2019
Still struggling with my C2084 error.
I have removed all :
#include <wx/msw/winundef.h>
from my headers except one in the Main.h one.
I still have the two C2084 error. And both are pointing to the Following piece of code in winundef.h :
I'll try to figure out why it's called twice in my program (my part of job) but I don't understand why this piece of code doesn't work !
Does anybody has an idea ?
Tanks in advance
I have removed all :
#include <wx/msw/winundef.h>
from my headers except one in the Main.h one.
I still have the two C2084 error. And both are pointing to the Following piece of code in winundef.h :
Code: Select all
#ifdef DrawText
#undef DrawText
#ifdef _UNICODE
inline int DrawText(HDC h, LPCWSTR str, int count, LPRECT rect, UINT format)
{
return DrawTextW(h, str, count, rect, format);
}
#else
inline int DrawText(HDC h, LPCSTR str, int count, LPRECT rect, UINT format)
{
return DrawTextA(h, str, count, rect, format);
}
#endif
#endif
Does anybody has an idea ?
Tanks in advance
Re: Moving to Visual Studio 2019
Eh, I did not notice that by purporse <wx/msw/winundef.h> does NOT have an include guard and can therefore be included several times.
Hence, I repeat my advice from previous post about making sure that defines, in particular UNICODE related ones, are same for all the files in your project and as when wxWidgets were built. Keep in mind that wxWidgets also include this header in its own files.
If anything else fails, you can tell MSVC to generate preprocessed files so you can see what and where gets actually included...
Hence, I repeat my advice from previous post about making sure that defines, in particular UNICODE related ones, are same for all the files in your project and as when wxWidgets were built. Keep in mind that wxWidgets also include this header in its own files.
If anything else fails, you can tell MSVC to generate preprocessed files so you can see what and where gets actually included...
Re: Moving to Visual Studio 2019
Where (in which order) do you include <wx/msw/winundef.h>? It should be after the last wx header and before any other headers.
Please try to recreate the error with the smallest amount of code, e.g. by modifying the "minimal" sample that comes with wxWidgets.
Please try to recreate the error with the smallest amount of code, e.g. by modifying the "minimal" sample that comes with wxWidgets.
Use the source, Luke!
Re: Moving to Visual Studio 2019
Thanks for the answers.
When you mean ; " It should be after the last wx header and before any other headers."
does it apply to the whole project or file by file ? There are 16 files in my program. In some of them, I need to declare the "wx.h" to compile them successfully. Thus, during the overall compilation process, it will be recalled after the winundef.h one.
I must confess I am not clear with the linking process.
When you mean ; " It should be after the last wx header and before any other headers."
does it apply to the whole project or file by file ? There are 16 files in my program. In some of them, I need to declare the "wx.h" to compile them successfully. Thus, during the overall compilation process, it will be recalled after the winundef.h one.
I must confess I am not clear with the linking process.
Re: Moving to Visual Studio 2019
For each source file. For example:
Code: Select all
// wx headers
#include "wx/wx.h"
#include "wx/filesys.h"
// your own headers that use wxWidgets classes
#include "aaaa.h"
#include "bbbb.h"
// winundef if necessary
#include <wx/msw/winundef.h>
// other non wx-related headers
#include "somethirdparty.h"
Use the source, Luke!
Re: Moving to Visual Studio 2019
Thanks a lot. That's clear. I'll try tonight.
Re: Moving to Visual Studio 2019
Hello
I'm still stuck with my program. I went through the 17 header files of it and put every include declaration in the right order :
include wx headers
include headers of files using wx
include winundef
include headers of other files
Then I try to remove the winudef include declaration file by file, starting by the "top of the tree".
Here is what happens:
-> Removing winundef from all headers except in "main.h" doesn't change anything. I still have the two "C2084 function DrawText already have a body" errors.
-> Removing winundef from all headers includng the "main.h" one clear both errors but I now have 2970 LNK 20001 errors: unresolved external symbol "class wxEventTypeTag<class wxCloseEvent> const wxEVT_CLOSE_WINDOW"...
or any other wx class.
The winundef.h file is obviously putting a mess during the compilation, but removing it is worst !
I'm still stuck with my program. I went through the 17 header files of it and put every include declaration in the right order :
include wx headers
include headers of files using wx
include winundef
include headers of other files
Then I try to remove the winudef include declaration file by file, starting by the "top of the tree".
Here is what happens:
-> Removing winundef from all headers except in "main.h" doesn't change anything. I still have the two "C2084 function DrawText already have a body" errors.
-> Removing winundef from all headers includng the "main.h" one clear both errors but I now have 2970 LNK 20001 errors: unresolved external symbol "class wxEventTypeTag<class wxCloseEvent> const wxEVT_CLOSE_WINDOW"...
or any other wx class.
The winundef.h file is obviously putting a mess during the compilation, but removing it is worst !
Re: Moving to Visual Studio 2019
Having winundef in header files is definitely dangerous, because it could make it impossible to assure the proper order. If possible it should be in source files only.Removing winundef from all headers except in "main.h" doesn't change anything.
But i don't believe anymore that that is the main problem. There must be something special about VS2019.
Please try to reproduce it in a minimal sample. Otherwise it will be hard or impossible to find a solution.
You should also try with the latest wxWidgets version from Git. It's possible that it already contains some fixes for VS2019.
Use the source, Luke!
Re: Moving to Visual Studio 2019
Next step : it reminds me an error I already met when I was a beginner. I am down to 79 LNK 2019 errors. I think I am close to the top of the mountain .
Re: Moving to Visual Studio 2019
BTW: Check the C++ preprocessor symbols and make sure that both UNICODE and _UNICODE are defined.
Use the source, Luke!