-4

Getting error i freetds headers when i include them in my VS 2017 c++ project

in tds.h when i include that in my project

    include\tds.h(1331): error C3646: 's': unknown override specifier
    include\tds.h(1331): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    include\tds.h(1641): error C2065: 'TDS_SYS_SOCKET': undeclared identifier
    include\tds.h(1641): error C2146: syntax error: missing ')' before identifier 's'

I am trying to use freetds 0.91.100 version in my c++ application which was built using VS 2010. It was fine then.

Now after migrating my C++ project to VS 2017 i am getting strange errors. I have built freetds lib as well in VS 2017.

freetds has this declaration in tds_sysdep_private.h

#if !defined(__WIN32__) && !defined(_WIN32) && !defined(WIN32)
typedef int TDS_SYS_SOCKET;
#define INVALID_SOCKET -1
#define TDS_IS_SOCKET_INVALID(s) ((s) < 0)
#else
typedef SOCKET TDS_SYS_SOCKET;
#define TDS_IS_SOCKET_INVALID(s) ((s) == INVALID_SOCKET)
#endif

and the tds.h has

struct tds_socket
{
TDS_SYS_SOCKET s;       /**< tcp socket, INVALID_SOCKET if not connected */
}

And the error is on this TDS_SYS_SOCKET declaration

My code include this header this way.

tdsloader.h

using namespace std;
#if defined (__cplusplus)
extern "C" {
#endif
#include "tds.h"
#if defined (__cplusplus)
}
#endif

As per the declaration of TDS_SYS_SOCKET in tds_sysdep_private.h , in case of windows build it is defined as SOCKET which is from winsock2.h

I read in other threads that the order of header file includion is important and i made sure that winsock2.h is included before windows.h or any other windows header file.

Now that SOCKET from winsock2.h is typedef UINT_PTR SOCKET;

which in an unsigned , why is VS 2017 not able to recognize the type ?

Build should go through smoothly as it did in VS 2010.

Now with VS 2017 it shows build errors.

1 Answers1

0

Here's the include order that works fine with VS 2017:

#include <tds_sysdep_private.h>
#include <tds.h>

alternatively you can:

#define _FREETDS_LIBRARY_SOURCE
#include <tds.h>
Marcin Zawiejski
  • 1,123
  • 1
  • 9
  • 23
  • this order should be followed in the cpp where we use tds ? you have not modified anything inside the freetds lib header files ? what version of freetds are you using ? – Deepak Selvakumar Feb 12 '19 at 11:14
  • It's for freetds version 0.91.100, no changes to the header files. In fact you don't need to include WinSock2.h and Windows.h because tds_sysdep_private.h already includes them. – Marcin Zawiejski Feb 12 '19 at 11:27
  • i am using the same version 0.91.100. Yes, tds_sysdep_private.h includes winsoc2.h and windows.h. and tds.h includes tds_sysdep_private.h. Hence, it is okay to only include tds.h, Correct ? as you have mentioned in the second option. – Deepak Selvakumar Feb 12 '19 at 13:23
  • Yes, it seems correct to include only tds.h but you have to #define _FREETDS_LIBRARY_SOURCE as this causes tds.h to include tds_sysdep_private.h. – Marcin Zawiejski Feb 12 '19 at 17:48