I am working on a project where I have to support IPv6 addressing scheme. This requires me to replace winsock.h with winsock2.h to make IP-version independent calls. Initially, I faced redefinition related errors which I could remove by employing solutions available online (placing #include <winsock2.h> before #include <windows.h>; including #define_WINSOCKAPI_). However, I am still getting errors like:
2>../include\obsocket.h(171) : error C2143: syntax error : missing '}' before 'constant'
2>../include\obsocket.h(171) : error C2059: syntax error : 'constant'
2>../include\obsocket.h(171) : error C2143: syntax error : missing ';' before '}'
2>../include\obsocket.h(171) : error C2238: unexpected token(s) preceding ';'
2>../include\obsocket.h(173) : error C2065: 'ShutdownType' : undeclared identifier
2>../include\obsocket.h(177) : error C2146: syntax error : missing ';' before identifier 'GetDescriptor'
2>../include\obsocket.h(177) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
2>../include\obsocket.h(177) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
2>../include\obsocket.h(177) : error C2065: '_sock' : undeclared identifier
2>../include\obsocket.h(179) : error C2065: '_timeout' : undeclared identifier
2>../include\obsocket.h(180) : error C2065: '_use_blocking_calls' : undeclared identifier
2>../include\obsocket.h(181) : error C2065: '_req_pending' : undeclared identifier
2>../include\obsocket.h(185) : error C2270: 'ToString' : modifiers not allowed on nonmember functions
2>../include\obsocket.h(187) : error C2059: syntax error : 'private'
2>../include\obsocket.h(189) : error C2146: syntax error : missing ';' before identifier '_sock'
2>../include\obsocket.h(189) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
2>../include\obsocket.h(189) : error C2086: 'int SOCK_TYPE' : redefinition
2>../include\obsocket.h(177) : see declaration of 'SOCK_TYPE'
2>../include\obsocket.h(189) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
2>../include\obsocket.h(189) : error C2371: '_sock' : redefinition; different basic types
2>../include\obsocket.h(199) : error C2371: '_use_blocking_calls' : redefinition; different basic types
2>../include\obsocket.h(200) : error C2371: '_timeout' : redefinition; different basic types
2>../include\obsocket.h(201) : error C2371: '_req_pending' : redefinition; different basic types
2>../include\obsocket.h(203) : error C2146: syntax error : missing ')' before identifier 'sock'
2>../include\obsocket.h(203) : error C2146: syntax error : missing ';' before identifier 'sock'
2>../include\obsocket.h(203) : error C2371: 'SOCK_TYPE' : redefinition; different basic types
I've made sure that winsock.h is not getting included anywhere during the build (by enabling show includes during the build).
Here is the code for obsocket.h:
#ifndef _obsocket_h
#define _obsocket_h
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
//#include <winsock.h>
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#endif
class ObSocket {
public:
#ifdef _WIN32
typedef SOCKET SOCK_TYPE;
#else
typedef int SOCK_TYPE;
#endif
ObSocket();
~ObSocket();
enum ShutdownType { SD_INCOMING = 0, SD_OUTGOING = 1, SD_BOTH = 2 };
ObStatus Shutdown(ShutdownType);
ObStatus Close();
bool IsValid();
SOCK_TYPE GetDescriptor() { return _sock; }
void NonBlocking(int timeout);
inline int GetTimeout( ) { return _timeout; }
inline bool IsBlocking( ) { return _use_blocking_calls; }
inline int IncPendingReq(int i = 1) { _req_pending += i; return _req_pending; }
inline int DecPendingReq(int i = 1) { _req_pending -= i; return _req_pending; }
inline int GetPendingReq( ) { return _req_pending; }
ObString& ToString(ObString& strClass) const;
private:
SOCK_TYPE _sock;
ObInetAddress _addr;
char _my_addr[20];
in_port_t _my_port;
char _remote_addr[20];
in_port_t _remote_port;
bool _use_blocking_calls;
int _timeout;
int _req_pending;
ObSocket(SOCK_TYPE sock);
void SetAddr(sockaddr_in& inAddr, const ObInetAddress& addr, in_port_t port);
void ReallocFileDescriptor();
ObSocket(const ObSocket&);
ObSocket& operator=(const ObSocket&);
static void Initialize();
static void Finalize();
};
Can anyone help in pointing out what could be going wrong?
Related
I tried to compile OpenVDB on Windows11(VS2017), but confusing error occurs:
Error C2676 Binary '<': 'const _Ty' does not define the operator or a conversion to a type that can be received by a predefined operator openvdb_shared
Error C2056 invalid expressions
Error C2088 invalid for class
It points to <algorithm.h> file, line 5386: "_NOEXCEPT_COND(_NOEXCEPT_OPER(_Left < _Right))".
#pragma warning(push)
#pragma warning(disable: 28285) // (syntax error in SAL annotation, occurs when _Ty is not an integral type)
template<class _Ty>
_Post_equal_to_(_Left < _Right ? _Right : _Left)
_NODISCARD constexpr const _Ty& (max)(const _Ty& _Left, const _Ty& _Right)
_NOEXCEPT_COND(_NOEXCEPT_OPER(_Left < _Right))
{ // return larger of _Left and _Right
if (_Left < _Right)
{
_STL_ASSERT(!(_Right < _Left), "invalid comparator");
return (_Right);
}
return (_Left);
}
and anothor fatal error:
fatal error LNK1104: can not open file “....\openvdb\openvdb\Debug\openvdb.lib”
I download OpenVDB source code and dependencies by git and vcpkg following the manual OpenVDB. I have no idea about how to fix those problems. Any suggestions or solution would be greatly appreciated!!!
I am trying to find EFI partition using CM_Get_Device_ID_ListW(), CM_Get_DevNode_PropertyW(), and ZwDeviceIoControlFile() Windows API. This is a shell application only. I used stdio to print on terminal. Below is the order of adding all header files. I tried to include following files:
#include <WINDOWS.h>
#include <initguid.h>
#include <devguid.h>
#include <devpkey.h>
#include <diskguid.h>
#include <stdio.h>
#include <cfgmgr32.h>
#include <Wdm.h>
I am using Windows 7, 64-bit, Visual Studio 2010. In VS2010 I set the include path:
F:\Programs\WINDDK\7600.16385.1\inc;F:\Programs\WINDDK\7600.16385.1\inc\api;F:\Programs\WINDDK\7600.16385.1\inc\crt;F:\Programs\WINDDK\7600.16385.1\inc\ddk;
Lib path:
F:\Programs\WINDDK\7600.16385.1\lib\win7\i386\
I get Compile Errors like:
f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(128): warning C4005: 'MAX_NATURAL_ALIGNMENT' : macro redefinition
f:\programs\winddk\7600.16385.1\inc\api\winnt.h(109) : see previous definition of 'MAX_NATURAL_ALIGNMENT'
f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(161): warning C4005: 'PROBE_ALIGNMENT' : macro redefinition
f:\programs\winddk\7600.16385.1\inc\api\winnt.h(142) : see previous definition of 'PROBE_ALIGNMENT'
f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(614): error C2011: '_PROCESSOR_NUMBER' : 'struct' type redefinition
f:\programs\winddk\7600.16385.1\inc\api\winnt.h(493) : see declaration of '_PROCESSOR_NUMBER'
f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(625): error C2011: '_GROUP_AFFINITY' : 'struct' type redefinition
f:\programs\winddk\7600.16385.1\inc\api\winnt.h(504) : see declaration of '_GROUP_AFFINITY'
f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(882): error C2011: '_FLOAT128' : 'struct' type redefinition
f:\programs\winddk\7600.16385.1\inc\api\winnt.h(630) : see declaration of '_FLOAT128'
f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(933): error C2011: '_LARGE_INTEGER' : 'union' type redefinition
f:\programs\winddk\7600.16385.1\inc\api\winnt.h(677) : see declaration of '_LARGE_INTEGER'
f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(951): error C2011: '_ULARGE_INTEGER' : 'union' type redefinition
f:\programs\winddk\7600.16385.1\inc\api\winnt.h(695) : see declaration of '_ULARGE_INTEGER'
f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(973): error C2011: '_LUID' : 'struct' type redefinition
f:\programs\winddk\7600.16385.1\inc\api\winnt.h(717) : see declaration of '_LUID'
f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(1070): error C2084: function 'ULONGLONG Int64ShllMod32(ULONGLONG,DWORD)' already has a body
f:\programs\winddk\7600.16385.1\inc\api\winnt.h(771) : see previous definition of 'Int64ShllMod32'
f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(1086): error C2084: function 'LONGLONG Int64ShraMod32(LONGLONG,DWORD)' already has a body
f:\programs\winddk\7600.16385.1\inc\api\winnt.h(778) : see previous definition of 'Int64ShraMod32'
f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(1102): error C2084: function 'ULONGLONG Int64ShrlMod32(ULONGLONG,DWORD)' already has a body
f:\programs\winddk\7600.16385.1\inc\api\winnt.h(785) : see previous definition of 'Int64ShrlMod32'
f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(1318): warning C4005: 'UNICODE_STRING_MAX_BYTES' : macro redefinition
f:\programs\winddk\7600.16385.1\inc\api\winnt.h(957) : see previous definition of 'UNICODE_STRING_MAX_BYTES'
f:\programs\winddk\7600.16385.1\inc\api\ntdef.h(1358): error C2011: '_LIST_ENTRY' : 'struct' type redefinition
f:\programs\winddk\7600.16385.1\inc\api\winnt.h(966) : see declaration of '_LIST_ENTRY'....
Can anyone help to resolve this?
I'm trying to compile C programs in VS2010 Professional using cl.exe (64bit command line). Getting strange errors in VS2010 or VS2008. Same Code compiles & runs in GNU gcc without a problem (Cygwin). Any ideas? Can't go any further with the real thing until I understand the problem here. Thanks!
filename: testC.c
cl.exe testC.c
#include<stdio.h>
#include <stdlib.h>
typedef double Td;
int main(int argc, char *argv[])
{
FILE *fp;
if ( (fp=fopen("junk_out.txt","w")) == NULL ){
printf("Cannot open file.\n");
exit(1);
}
fprintf(fp,"%f \n",3.1420);
fclose(fp);
Td x=3.14;
Td *a;
a = &x;
printf("%f \n",a);
printf("%f \n",x);
printf("%f \n",*a);
return 0;
}
Here is the output:
testC.c(18): error C2275: 'Td' : illegal use of this type as an expression
testC.c(5) : see declaration of 'Td'
testC.c(18): error C2146: syntax error : missing ';' before identifier 'x'
testC.c(18): error C2065: 'x' : undeclared identifier
testC.c(18): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
testC.c(19): error C2275: 'Td' : illegal use of this type as an expression
testC.c(5) : see declaration of 'Td'
testC.c(19): error C2065: 'a' : undeclared identifier
testC.c(21): error C2065: 'a' : undeclared identifier
testC.c(21): error C2065: 'x' : undeclared identifier
testC.c(21): warning C4047: '=' : 'int' differs in levels of indirection from 'int *'
testC.c(22): error C2065: 'a' : undeclared identifier
testC.c(23): error C2065: 'x' : undeclared identifier
testC.c(24): error C2065: 'a' : undeclared identifier
testC.c(24): error C2100: illegal indirection
You have to define every variable at the top of a function if you compile your code with the C compiler from VS2010.
#include <stdio.h>
#include <stdlib.h>
typedef double Td;
int main(int argc, char *argv[])
{
FILE *fp;
Td x;
Td *a;
if ( (fp=fopen("junk_out.txt","w")) == NULL )
{
printf("Cannot open file.\n");
exit(1);
}
fprintf(fp,"%f \n",3.1420);
fclose(fp);
x=3.14;
a = &x;
printf("%f \n",a);
printf("%f \n",x);
printf("%f \n",*a);
return 0;
}
In C++ you can define everywhere you want.
OS: Win7
IDE: Visual Studio 2010
Boost Version: 1.47
I'm new to Boost and what I'm trying is very simple. I've created a single thread in a header file and tried putting it to sleep. But I can't get it working. Here is the code and compilation errors
main.h -
#pragma once
#include <conio.h>
#include <boost\thread.hpp>
boost::posix_time::seconds workTime ( 120 );
boost::this_thread::sleep ( workTime );
main.cpp
#include "main.h"
void main ( void ) {
_getch();
};
Output -
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2365: 'boost::this_thread::sleep' : redefinition; previous definition was 'function'
error C2491: 'boost::this_thread::sleep' : definition of dllimport data not allowed
error C2482: 'boost::this_thread::sleep' : dynamic initialization of 'thread' data not allowed
Using the following code now, all in main.cpp:
#include <boost\thread.hpp>
#include <conio.h>
void thread_func()
{
boost::posix_time::seconds workTime ( 120 );
boost::this_thread::sleep ( workTime );
}
int main(int argc, char* argv[])
{
boost::thread t(thread_func);
_getch();
}
Receiving the following errors:
1>LIBCMTD.lib(dbgheap.obj) : error LNK2005: __heap_alloc already defined in LIBCMT.lib(malloc.obj)
1>LIBCMTD.lib(dbgheap.obj) : error LNK2005: __recalloc already defined in LIBCMT.lib(recalloc.obj)
1>LIBCMTD.lib(dbgheap.obj) : error LNK2005: __msize already defined in LIBCMT.lib(msize.obj)
1>LIBCMTD.lib(dbghook.obj) : error LNK2005: __crt_debugger_hook already defined in LIBCMT.lib(dbghook.obj)
1>LIBCMTD.lib(isctype.obj) : error LNK2005: __isctype_l already defined in LIBCMT.lib(isctype.obj)
1>LIBCMTD.lib(isctype.obj) : error LNK2005: __isctype already defined in LIBCMT.lib(isctype.obj)
1>LINK : warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library
1>fatal error LNK1169: one or more multiply defined symbols found
You are calling boost::this_thread::sleep ( workTime ) outside of any control flow. You should do something like:
void thread_func()
{
boost::posix_time::seconds workTime ( 120 );
boost::this_thread::sleep ( workTime );
}
int main(int argc, char* argv[])
{
boost::thread t(thread_func);
_getch();
}
First: sorry my bad English =((
Sencond:
here's my code in "Global.h":
#pragma once
class GlobalVariable
{
public:
GlobalVariable(void);
~GlobalVariable(void);
//------------------------------------------------
public:
double pixelWidth; // do rong cua 1 pixel tren Viewport
double pixelHeigh; // do cao cua 1 pixel tren Viewport
public:
Point oldPoint, tempPoint;
Circle oldCir, tempCir;
DaGiac oldDaGiac, tempDaGiac;
Color oldObjColor,tempObjColor, OxyColor;
};
class Point
{
public:
Point(void);
~Point(void);
double x,y; // toạ độ (x,y)
};
class Color
{
public:
Color(void);
~Color(void);
double R,G,B; // màu (R,G,B)
};
class DaGiac
{
public:
DaGiac(void);
~DaGiac(void);
int numOfPeak; //so' dinh?
Point peakArr[10]; // ve da giac canh so dinh toi da la 10
};
class Circle
{
public:
Circle(void);
~Circle(void);
Point centre;
double radius;
};
and I have some eror :(
------ Build started: Project: GAS, Configuration: Debug Win32 ------
Compiling...
GlobalVariable.cpp
e:\documents\bin\gas_project\globalvariable.h(15) : error C2146: syntax error : missing ';' before identifier 'oldPoint'
e:\documents\bin\gas_project\globalvariable.h(15) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(15) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(15) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(16) : error C2146: syntax error : missing ';' before identifier 'oldCir'
e:\documents\bin\gas_project\globalvariable.h(16) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(16) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(16) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(17) : error C2146: syntax error : missing ';' before identifier 'oldDaGiac'
e:\documents\bin\gas_project\globalvariable.h(17) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(17) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(17) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(18) : error C2146: syntax error : missing ';' before identifier 'oldObjColor'
e:\documents\bin\gas_project\globalvariable.h(18) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(18) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(18) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(18) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Build log was saved at "file://e:\Documents\BIN\GAS_Project\Debug\BuildLog.htm"
GAS - 17 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
But after I delete the GlobalVariable class! Only class Point, Color, DaGiac, Circle exist! It has no eror!
Tell me why? And how to corect that error ? Please =((
The compiler can't "see" the other classes, because they're defined after the GlobalVariable class. Move the whole GlobalVariable class to the bottom of the file so that all of the classes it depends on will be defined when it needs them.