I am trying to compile a code
#include <Header1.h>
#include "Header2..h"
#include <ctype.h>
Header1.h includes winsock.h and Header2.h includes windows.h
I am using winsock.h instead of winsock2.h because winsock2.h was showing redefinition errors, which is a standard error, but I was not able to fix that using the solutions provided to them.
I have also tried including ws2tcpip.h, but it is giving tons of redefinition errors in winsock.h.
I am getting 12 errors in this Module
error C3861: 'close': identifier not found
error C2664: 'setsockopt' : cannot convert parameter 4 from 'timeval *' to 'const char *'
error C2065: 'socklen_t' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'optionLength'
error C2065: 'optionLength' : undeclared identifier
error C2065: 'optionLength' : undeclared identifier
error C2664: 'setsockopt' : cannot convert parameter 4 from 'int32 *' to 'const char *'
error C2065: 'MSG_WAITALL' : undeclared identifier
error C2664: 'recvfrom' : cannot convert parameter 2 from 'uint8 *' to 'char *'
error C2065: 'ERROR_END_OF_STREAM' : undeclared identifier
error C3861: 'close': identifier not found
error C3861: 'close': identifier not found
Add #include <winsock2.h> or #include <ws2tcpip.h> on the top of includes.
#include <winsock2.h>
#include <Header1.h>
#include "Header2.h"
#include <ctype.h>
winsock.h should be included first. And I notice that your code seems to be unixish code. On windows, closesocket is used for closing socket.
Also, #define WIN32_LEAN_AND_MEAN before anything else. That often helps.
Also, in some cases helps this (issues with ws2tcpip identifier error):
#pragma once
#define _WIN32_WINNT 0x500
#include <winsock2.h>
#include <WS2tcpip.h>
#pragma comment(lib, "WS2_32.Lib")
Related
I am writing a program on Microsoft Visual C++ 2010 Express and am having an issue with my class object. I keep getting undeclared identifier and missing ';' before identifier errors and I'm not sure what is causing the problem.
I've checked my headers for any mistakes and have made several changes to see if it would fix the problem with no luck.
// RightJust class declaration that right justifies the numbers.
#ifdef RIGHTJUST_H_
#define RIGHTJUST_H_
#include "stdafx.h"
#include <iostream>
#include <string>
#include <cstring>
using namespace System;
using namespace std;
class RightJust
{
private:
int x, totalWH1, totalWH2, totalWH3, totalWH4;
int itemT1, itemT2, itemT3, itemT4, itemT5; // Holds item totals
string WH1, WH2, WH3, WH4;
int num[4][5]; // Array containing data
public:
RightJust();
int warehouseLen();
void rightJustZero();
void rightJustLess();
};
// This program asks to user to choose a report type and displays
// the report type chosen.
#include "stdafx.h"
#include <iostream>
#include "RightJust.h"
#include <string>
#include <cstring>
using namespace System;
using namespace std;
int main
{
RightJust type;
if(reportType == 1)
{
type.rightJustZero();
}
else if(reportType == 2)
{
type.rightJustLess();
}
}
I just want a solution to get rid of all the error messages to see if my program is working how I needed it to work.
Test3.cpp
1>Test3.cpp(24): error C2065: 'RightJust' : undeclared identifier
1>Test3.cpp(24): error C2146: syntax error : missing ';' before identifier 'type'
1>Test3.cpp(24): error C2065: 'type' : undeclared identifier
1>Test3.cpp(27): error C2065: 'type' : undeclared identifier
1>Test3.cpp(27): error C2228: left of '.rightJustZero' must have class/struct/union
1> type is ''unknown-type''
1>Test3.cpp(31): error C2065: 'type' : undeclared identifier
1>Test3.cpp(31): error C2228: left of '.rightJustLess' must have class/struct/union
1> type is ''unknown-type''
The include guard in your header is wrong. It should be
#ifndef RIGHTJUST_H_
Using #ifdef RIGHTJUST_H_ will skip the code if the symbol is not defined.
You should not have #include "stdafx.h" in your .h files. And since you seem to be using Visual Studio, you can just use #pragma once instead of the include guard.
I've integrated all the needed files to use freetype-gl.hdirectly into my OpenGL project, but when I try to build the program, I receive 262 errors complaining aboutwglew.h. A sample of the errors:
error C2143: syntax error : missing ')' before '*' c:\bar\includes\glew110\include\gl\wglew.h 113 1 Foo
error C2143: syntax error : missing ';' before '*' c:\bar\glew110\include\gl\wglew.h 113 1 Foo
error C2059: syntax error : ')' c:\bar\includes\glew110\include\gl\wglew.h 113 1 Foo
error C2065: 'HDC' : undeclared identifier c:\bar\glew110\include\gl\wglew.h 113 1 Foo
error C2146: syntax error : missing ')' before identifier 'hDC' c:\bar\includes\glew110\include\gl\wglew.h 113 1 Foo
And in my class, just this header causes the problem with wglew.h:
#include "freetype-gl.h" // causes all the errors
This solution solved a wglew error for me, not sure if it's the same problem.
Try adding the wglew.h include line to the same file as your other include line for freetype-gl.h, and in this order:
#include <Windows.h> // maybe not needed
#define GLEW_STATIC // maybe not needed
#include "GL/glew.h"
#include "GL/wglew.h"
#include "freetype-gl.h"
// other includes below
#include "stdafx.h"
#include "stdio.h"
#include <iostream>
#include "math.h"
#include <complex>
#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
#include <io.h>
void multiple(complex**,complex*,complex*);
void solve(complex**, complex*, complex*, int);
As I typed the above-mentioned code, we receive the following errors:
error C2065: 'complex' : undeclared identifier
error C2059: syntax error : ','
Many thanks for your time,
The class is located in the namespace std as well as all other C++ standard library classes / functions. So you have to change complex to std::complex<T> (don't forget the template parameter!).
I googled the error lines of my problem and got hardly any hits and I don't speak russian. I also found this, but it doesn't seem to help me.
This is my code
#include <iostream>
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
int main() {
boost::asio::io_service io;
boost::asio::deadline_timer t(io,boost::posix_time::seconds(5));
t.wait();
std::cout << "Hello World" << std::endl;
return 0;
}
These be my error messages:
1>------ Build started: Project: ConsoleApplication1, Configuration: Debug Win32 ------
1> Main.cpp
1>c:\sdk\boost\asio\detail\impl\win_thread.ipp(52): error C2039: 'QueueUserAPC' : is not a member of '`global namespace''
1>c:\sdk\boost\asio\detail\impl\win_thread.ipp(52): error C3861: 'QueueUserAPC': identifier not found
1>c:\sdk\boost\asio\detail\impl\win_object_handle_service.ipp(374): error C3861: 'RegisterWaitForSingleObject': identifier not found
1>c:\sdk\boost\asio\detail\impl\win_object_handle_service.ipp(416): error C3861: 'RegisterWaitForSingleObject': identifier not found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Any insights would be appreciated, thanks!
EDIT
Adding #include <Windows.h> before the headers changed the error messages to
1>c:\program files (x86)\windows kits\8.0\include\um\prsht.h(607): error C2146: syntax error : missing ';' before identifier 'hdr'
1>c:\program files (x86)\windows kits\8.0\include\um\prsht.h(607): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\windows kits\8.0\include\um\windows.h(247): warning C4193: #pragma warning(pop) : no matching '#pragma warning(push)'
1>c:\sdk\boost\asio\detail\socket_types.hpp(22): fatal error C1189: #error : WinSock.h has already been included
prsht.h:
tracking that down lead me to find this:
typedef struct _PSHNOTIFY
{
NMHDR hdr; //line 607 NMHDR is undefined.
LPARAM lParam;
} PSHNOTIFY, *LPPSHNOTIFY;
Not real sure where to go from here.
I am unable to compile my code when using a CStdioFile type. I have included the afx.h header file but I am still receiving errors. What I am trying to do is write a cstring that contains an entire xml document to file. This cstring contains comments inside of it, but when I use other objects such as wofstream to write it to file, these comments are striped out for some reason. So that is why I am trying to write this to file using CStdioFile now. If anyone can help me out as to why I cannot compile my code using CStdioFile, or any other way to write a cstring that contains xml comments to file, please let me know! Below is my code using CStdioFile:
CStdioFile xmlFile;
xmlFile.Open( "c:\\test.txt", CFile::modeCreate | CFile::modeWrite | CFile::typeText );
xmlFile.WriteString( m_sData );
xmlFile.Close();
And my errors:
error C2065: 'CStdioFile' : undeclared identifier
error C2065: 'modeCreate' : undeclared identifier
error C2065: 'modeWrite' : undeclared identifier
error C2065: 'typeText' : undeclared identifier
error C2065: 'xmlFile' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'xmlFile'
error C2228: left of '.Close' must have class/struct/union type type is ''unknown-type''
error C2228: left of '.Open' must have class/struct/union type type is ''unknown-type''
error C2228: left of '.WriteString' must have class/struct/union type type is ''unknown-type''
error C2653: 'CFile' : is not a class or namespace name
error C2653: 'CFile' : is not a class or namespace name
error C2653: 'CFile' : is not a class or namespace name
error C3861: 'xmlFile': identifier not found, even with argument-dependent lookup
error C3861: 'xmlFile': identifier not found, even with argument-dependent lookup
error C3861: 'xmlFile': identifier not found, even with argument-dependent lookup
Are you really including <afx.h>? Is it the right axf.h (you'd have to have something pretty odd going on on your system for it to not be)? What compiler version are you using?
This small program compiles and runs fine with VS2010 and VS2008:
#include <afx.h>
#include <tchar.h>
int main()
{
CStdioFile xmlFile;
LPCTSTR m_sData = _T("Testing 123\n");
xmlFile.Open( _T("c:\\temp\\test.txt"), CFile::modeCreate | CFile::modeWrite | CFile::typeText );
xmlFile.WriteString( m_sData );
xmlFile.Close();
}
What happens with it on your system?