At the very beginning I include the following files and everything goes fine with the bind function
#include "stdafx.h"
#undef UNICODE
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
bind function
iResult = bind(ListenSocket, result->ai_addr, (int)result->ai_addrlen);
Things start messing up when I include the mysql libraries as well
#include "stdafx.h"
#undef UNICODE
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
//mysql connections
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
I started debug and it give me this error
IntelliSense: no suitable conversion function from "std::_Bind<false, void, SOCKET &, sockaddr *&, int>" to "int" exists
error C2440: '=' : cannot convert from 'std::_Bind<false,void,SOCKET &,sockaddr *&,int>' to 'int'
Please help.
I guess the problem is not in including the Mysql library, i got this problem once and i fixed it removing the
using namespace std;
or another solution is to call bind from the global namespace to avoid this kind of problems;
i forgot to write that calling bind from the global namespace is done like this :
::bind(...);
Hope this helps.
Related
#include <DriverSpecs.h>
_Analysis_mode_(_Analysis_code_type_user_code_)
#define INITGUID
//#include<iostream>
#include <windows.h>
#include <strsafe.h>
#include <cfgmgr32.h>
#include <stdio.h>
#include <stdlib.h>
#include "public.h"
When I tried to use <iostream> in a sample driver solution I got an error.
I'd like to know if is it possible to get input or output while a driver is running.
I have a CPP project in Visual Studio, I'm getting the following message when I try to build the solution:
1>c:\program files (x86)\windows kits\8.1\include\um\winnt.h(147): fatal error C1189: #error : "No Target Architecture"
The contents of stdafx.h:
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#include <ctime>
#include <time.h>
#include <iostream>
#include <profileapi.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <Windows.h>
What's missing?
In the end I found that removing the headers:
profileapi.h
sys/types.h
Resolved the issue and the project now builds without warning or error.
Thank you Dai, the better solution:
#include "targetver.h"
#include <Windows.h>
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <chrono>
#include <ctime>
#include <time.h>
#include <fstream>
#include <profileapi.h>
#include <sys/stat.h>
#include <sys/types.h>
One of my script file(.scnp)included the following headers as follows.
#include <stdio.h>
#include "kel.h"
#include "process.h"
#include "sigtypes.h"
#include "ScriptInterface.h"
#include "../saf/SAF_Scripts.h"
This type of header files include gives an error in GDB saying
"symbol lookup error: /xxx/xxxx.so: undefined symbol:
_Z16KEL_MEM_AllocateP19KEL_MEM_tPoolHandlej.
Included file after
#include <stdio.h>
#include "ScriptInterface.h"
#include "kel.h"
#include "process.h"
#include "sigtypes.h"
#include "../saf/SAF_Scripts.h"
ScriptInterface.h
extern "C"
{
#include "kel.h"
#include "process.h"
#if defined()
#include "sigtypes.h"
#endif
}
The scripts run successfully. What could be the problem? I have found the responsible method for this problem by using "c++filt" but don't know how to proceed further. Please help
I have a cpp file contains this include:
#include "twitServer.h"
and in twitServer.h I have:
#ifndef twitServer_twitServer_h
#define twitServer_twitServer_h
#include <string>
#include <map>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <cstring>
#include <netdb.h>
#include <errno.h>
#include <sstream>
#include <algorithm>
#include <ctime>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include "twitUser.h"
using namespace std;
void startServer(string port);
#endif
But the Xcode says for this line:
if ((rv = getaddrinfo(NULL, port, &hints, &ai)) != 0) {
fprintf(stderr, "selectserver: %s\n", gai_strerror(rv));
exit(1);
}
that the getaddrinfo is not defined... why that?
if the includes are in the cpp file it works fine how comes
Not sure how to fix your problem, but by convention, you should never include in the header file, because you might write code some day, needing your header file, but not all the includes.
Try including Ws2tcpip.h and see if that solves the problem. This is what MSDN has to say about it (see the requirements section)
http://msdn.microsoft.com/en-us/library/windows/desktop/ms738520%28v=vs.85%29.aspx
Also, let me say that this seems like an awful lot of header files included and some should not be matched unless you really know what you are doing. There are quite a bit of C++ headers (iostream (which is included twice by the way), cstdio, cstdlib, algorithm, list, string, ctime...) mixed with C headers (stdio.h, stdlib.h string.h). Maybe it's time for some late spring cleaning in there :)
I have a linux applications which sends data over UDP protocol. It uses these header files:
#include <stdio.h>
/* standard C i/o facilities */
#include <stdlib.h>
/* needed for atoi() */
#include <unistd.h>
/* defines STDIN_FILENO, system calls,etc */
#include <sys/types.h> /* system data type definitions */
#include <sys/socket.h> /* socket specific definitions */
#include <netinet/in.h> /* INET constants and stuff */
#include <arpa/inet.h> /* IP address conversion stuff */
#include <netdb.h>
#include <string.h> /* for string and memset etc */
/* gethostbyname */
#include <iostream>
#include <fstream>
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include <opencv/cxcore.h>
I want to make a WIndows version of my app. But some of the above header files do not work in WIndows, especially those for UDP.
Which header files should I substitute them for in Windows (Visual Studio 2010)?
UPDATE:
Ok, so my header now looks like this:
#include <iostream>
#include <fstream>
#include "stdafx.h"
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <winsock2.h>
I get this error when trying to compile (and many other similar errors):
Error 13 error C2011: 'fd_set' : 'struct' type redefinition c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winsock2.h 132 1 Client
At compile-time, you need to use Winsock2.h instead of the Unix headers.
At link-time, include ws2_32.lib to provide linkage to the required system DLL.
Comment out the include files that are "missing"
or put them into the following:
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN 1
#include <winsock2.h>
#include <windows.h>
#else
// unix includes here
#endif
You don't need most of those includes. The only file you will need is winsock2.h and link with ws2_32.lib.
So, for all networking stuff, just include winsock2.h.
You want to #include winsock2.h. One peculiarity, you need to #include before including anything else, including :
#include <winsock2.h>
#include <windows.h>