Search code examples
c++mysqlvisual-studio-2008wxwidgets

Huge amount of errors because of 1 header addition


I develop an application (in Visual Studio 2008), which communicate with the MySQL database and uses wxWidgets quite a lot. The problem is when I add the include file, where MySQL include files exist I get huge amount of errors.

This is the main file, where I include Database.h.

#include <boost/shared_ptr.hpp>
#include <wx/app.h>

#include <ConcreteBatchDialogView.h>
#include <ConcreteLoginDialogView.h>
#include <ConcreteInitDialogView.h>
#include <ConcreteKeyDataView.h>
#include <ConcreteProductDataView.h>
#include <ConcreteView.h>
#include <Controller.h>
#include <DummyModel.h>
#include <Revision.h>

#include <Database.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
     ...
     return 0;
}

Database.h has the following code:

#include <wx/string.h>
#include "DbTable.h"

class DbTable;

class Database
{
public:
    Database();
    ~Database();

    ....
}

And finally DbTable has includes of MySQL:

#include <my_global.h>
#include <mysql.h>

class DbTable
{
public:
     // CREATORS
     ~DbTable();

     MYSQL_ROW currentRow;    
     MYSQL_ROW *row;
}

So, the application compiles fine until I include the Database.h.

Please, check the logs:

Compiling...
main.cpp
f:\build\mysql\5_6_12\x32\include\my_config.h(263) : warning C4005: 'HAVE_STRNLEN' : macro redefinition
f:\build\wxwidgets\2_9_1\include\wx\wxcrtbase.h(252) : see previous definition of 'HAVE_STRNLEN'
c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(91) : warning C4005: 'AF_IPX' : macro redefinition
c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(460) : see previous definition of 'AF_IPX'
c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(127) : warning C4005: 'AF_MAX' : macro redefinition
c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(479) : see previous definition of 'AF_MAX'
c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(163) : warning C4005: 'SO_DONTLINGER' : macro redefinition
c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(402) : see previous definition of 'SO_DONTLINGER'
c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(206) : error C2011: 'sockaddr' : 'struct' type redefinition
c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(485) : see declaration of 'sockaddr'
c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(384) : error C2143: syntax error : missing '}' before 'constant'
c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(384) : error C2143: syntax error : missing ';' before 'constant'
c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(384) : error C2059: syntax error : 'constant'
c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(437) : error C2143: syntax error : missing ';' before '}'
c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(437) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(437) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(518) : warning C4005: 'IN_CLASSA' : macro redefinition
c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(287) : see previous definition of 'IN_CLASSA'
c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(524) : warning C4005: 'IN_CLASSB' : macro redefinition
c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(293) : see previous definition of 'IN_CLASSB'
c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(530) : warning C4005: 'IN_CLASSC' : macro redefinition
c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(299) : see previous definition of 'IN_CLASSC'
c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(541) : warning C4005: 'INADDR_ANY' : macro redefinition
c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(304) : see previous definition of 'INADDR_ANY'
c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(543) : warning C4005: 'INADDR_BROADCAST' : macro redefinition
c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(306) : see previous definition of 'INADDR_BROADCAST'
c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(577) : error C2011: 'sockaddr_in' : 'struct' type redefinition
c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(312) : see declaration of 'sockaddr_in'
c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(132) : error C2011: 'fd_set' : 'struct' type redefinition
c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(68) : see declaration of 'fd_set'
c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(167) : warning C4005: 'FD_SET' : macro redefinition
c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(102) : see previous definition of 'FD_SET'
c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(176) : error C2011: 'timeval' : 'struct' type redefinition
c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(111) : see declaration of 'timeval'
c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(232) : error C2011: 'hostent' : 'struct' type redefinition
c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(167) : see declaration of 'hostent'

I think this is pretty much enough, but there are much more.

Do you have any advise what to do with this?

I checked that it can be a problems of wxWidgets - MySQL compilation. I tried to separate them some how, but didn't help so far.


Solution

  • Probably the problem comes from the MySQL header files, which I included in some headers as well. Perhaps wxWidgets and MySQL doen't like each other.

    And actually the main thing what I use is MYSQL_ROW, which is actually

    typedef char **MYSQL_ROW.
    

    So, I decided to replace MYSQL_ROW to char ** in all headers and places, where I use it and add the headers

    #include <my_global.h>
    #include <mysql.h>
    

    only to database.cpp file.

    Kind of nasty hack, but helped to solve the issue.