I'm having the same error as Crypto++ giving a compiler error in algparam.h when compiling a game using Crypto++. The error is:
Error C2061: syntax error : identifier 'buffer' (at line 397)
Here is the code. It starts on line 390 an ends at line 411.
#if defined(DEBUG_NEW) && (_MSC_VER >= 1300)
# pragma push_macro("new")
# undef new
#endif
void MoveInto(void *buffer) const
{
AlgorithmParametersTemplate<T>* p = new(buffer) AlgorithmParametersTemplate<T>(*this);
CRYPTOPP_UNUSED(p); // silence warning
}
#if defined(DEBUG_NEW) && (_MSC_VER >= 1300)
# pragma pop_macro("new")
#endif
protected:
T m_value;
};
CRYPTOPP_DLL_TEMPLATE_CLASS AlgorithmParametersTemplate<bool>;
CRYPTOPP_DLL_TEMPLATE_CLASS AlgorithmParametersTemplate<int>;
CRYPTOPP_DLL_TEMPLATE_CLASS AlgorithmParametersTemplate<ConstByteArrayParameter>;
What is the problem and how do I fix it?
Here are the libraries I use:
boost 1.67 (tried 1.63 too)
sqlapi++
camp
mysqlcppconns
Here is the error message:
1>c:\local\cryptopp\algparam.h(397): error C2061: syntax error: identifier 'buffer'
1>c:\local\cryptopp\algparam.h(396): note: while compiling class template member function 'void CryptoPP::AlgorithmParametersTemplate<CryptoPP::ConstByteArrayParameter>::MoveInto(void *) const'
1>c:\local\cryptopp\algparam.h(411): note: see reference to class template instantiation 'CryptoPP::AlgorithmParametersTemplate<CryptoPP::ConstByteArrayParameter>' being compiled
Here is the function you are having trouble with from algparam.h:
395 void MoveInto(void *buffer) const
396 {
397 AlgorithmParametersTemplate<T>* p = new(buffer) AlgorithmParametersTemplate<T>(*this);
398 CRYPTOPP_UNUSED(p); // silence warning
399 }
I suspect one of the other libraries you are using is messing with the definition on new.
I believe you need to compile the source file but instead of producing an object file, you need to use either /P (Preprocess to a File) or /E (Preprocess to stdout). Once the file is processed take a look at the definition of new. From there work back to the library that is changing it.
In the comments you said you also use:
boost 1.67 (tried 1.63 too)
sqlapi++
camp
mysqlcppconns
Boost does some unusual things at times, and I would suspect boost as the problem.
Related
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.
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>
I'm working on a little C++ WinAPI wrapper. I'd like to create my own window and append my own controls to it.
I created 2 classes : Window and Control.
The problem is that I struggle to deal with the multiple header files, because the class Control needs the class Window and vice versa. When I compile my code, I get many errors..
Here are my files :
globals.h :
// globals.h
// I need this file to define a few constants and to include the main headers needed by my classes
#ifndef GLOBALS_H
#define GLOBALS_H
#include <windows.h>
#include <iostream>
#include <vector>
#include "window.h"
#define SOME_GLOBAL_CONSTANT 1
#endif
window.h :
// window.h
#ifndef WINDOW_H
#define WINDOW_H
#include "globals.h"
#include "control.h"
class Window
{
public:
Window(RECT windowRect);
virtual ~Window();
void appendChild(Control* child);
private:
RECT m_windowRect;
Control m_staticBackground;
std::vector<Control*> m_children;
};
#endif
window.cpp :
// window.cpp
#include "window.h"
Window::Window(RECT windowRect) : m_windowRect(windowRect)
{
std::cout << SOME_GLOBAL_CONSTANT << std::endl;
}
Window::~Window()
{
m_children.clear();
}
void Window::appendChild(Control* child)
{
m_children.push_back(child);
}
control.h :
// control.h
#ifndef CONTROL_H
#define CONTROL_H
#include "globals.h"
class Control
{
public:
Control(Window* parentWindow);
virtual ~Control();
private:
RECT m_controlRect;
Window* m_parentWindow;
};
#endif
control.cpp :
// control.cpp
#include "control.h"
Control::Control(Window* parentWindow) : m_controlRect({}), m_parentWindow(parentWindow)
{
std::cout << SOME_GLOBAL_CONSTANT << std::endl;
}
Control::~Control()
{}
And finally, main.cpp :
#include "globals.h"
class MyCustomControl : public Control
{
public:
MyCustomControl(Window* parentWindow) : Control(parentWindow)
{}
~MyCustomControl()
{}
};
class MyWindow : public Window
{
public:
MyWindow(RECT windowRect) : Window(windowRect)
{
kid1 = new MyCustomControl(this);
appendChild(kid1);
}
~MyWindow()
{
delete kid1;
}
private:
MyCustomControl* kid1;
};
int main()
{
MyWindow appWindow;
std::cout << SOME_GLOBAL_CONSTANT << std::endl;
return 0;
}
Here are all the compilation errors I get :
1>------ Build started: Project: include, Configuration: Debug Win32 ------
1>window.cpp
1>d:\visual studio 2017\projects\include\include\control.h(9): error C2061: syntax error: identifier 'Window'
1>d:\visual studio 2017\projects\include\include\control.h(14): error C2143: syntax error: missing ';' before '*'
1>d:\visual studio 2017\projects\include\include\control.h(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio 2017\projects\include\include\control.h(14): error C2238: unexpected token(s) preceding ';'
1>main.cpp
1>d:\visual studio 2017\projects\include\include\control.h(9): error C2061: syntax error: identifier 'Window'
1>d:\visual studio 2017\projects\include\include\control.h(14): error C2143: syntax error: missing ';' before '*'
1>d:\visual studio 2017\projects\include\include\control.h(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio 2017\projects\include\include\control.h(14): error C2238: unexpected token(s) preceding ';'
1>d:\visual studio 2017\projects\include\include\main.cpp(8): error C2664: 'Control::Control(const Control &)': cannot convert argument 1 from 'Window *' to 'const Control &'
1>d:\visual studio 2017\projects\include\include\main.cpp(8): note: Reason: cannot convert from 'Window *' to 'const Control'
1>d:\visual studio 2017\projects\include\include\main.cpp(8): note: No constructor could take the source type, or constructor overload resolution was ambiguous
1>d:\visual studio 2017\projects\include\include\main.cpp(32): error C2512: 'MyWindow': no appropriate default constructor available
1>d:\visual studio 2017\projects\include\include\main.cpp(13): note: see declaration of 'MyWindow'
1>control.cpp
1>d:\visual studio 2017\projects\include\include\window.h(13): error C2061: syntax error: identifier 'Control'
1>d:\visual studio 2017\projects\include\include\window.h(17): error C3646: 'm_staticBackground': unknown override specifier
1>d:\visual studio 2017\projects\include\include\window.h(17): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio 2017\projects\include\include\window.h(18): error C2065: 'Control': undeclared identifier
1>d:\visual studio 2017\projects\include\include\window.h(18): error C2059: syntax error: '>'
1>d:\visual studio 2017\projects\include\include\window.h(18): error C2976: 'std::vector': too few template arguments
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.10.25017\include\vector(700): note: see declaration of 'std::vector'
1>Generating Code...
1>Done building project "include.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Any help would be greatly appreciated.
Thank you in advance,
winapiwrapper.
Edit: I have also read this thread, but I couldn't solve my problem.
Welcome to programming. Strike down one error message and two shall take its place.
Well... Not really. What's happening is as you resolve one error, this reveals the errors that the precious errors were hiding.
First a PSA:
Don't write much code without compiling and testing. This way you have a smaller amount of code you need to check when something goes wrong. Start with a main function. Make sure it builds. Add the headers you need. Make sure it builds. Write a function for main to call. Make sure it builds. Repeat until program is finished. Trying to add too much all at once results in cascading storms of errors like you have experienced here.
Global include header files are usually a sucker bet. They often lead you into problems like the circular dependency you have here and make files include everything even when they don't have to. This can slow down build times.
Next, read the following link before continuing: Resolve header include circular dependencies
Now on with the answer:
window.h includes control.h. control .h includes window.h though global.h. This results in the Chicken and egg problem discussed in the above link. One of the headers is going to be included before the other and not be able to find the contents of the other file. Fortunately control.h only needs a reference to Window, not the whole thing, and this can be satisfied with a forward declaration and removing the global include file.
I'm not going to demonstrate cleaning this up. The process is well documented in the link.
This exposes hydra head number 2: Window contains Control m_staticBackground and does not explicitly initialize it. This results in the compiler hunting around for a default constructor for Control, something that does not exist.
Solution: Explicitly initialize m_staticBackground
Window::Window(RECT windowRect) : m_windowRect(windowRect),
m_staticBackground(this)
{
std::cout << SOME_GLOBAL_CONSTANT << std::endl;
}
BIG Mother Freaking note here: m_staticBackground(this) is dodgy as hell. this has not been fully constructed yet, so if you do more than simply store it in Control::Control (which is all you are currently doing) very bad, unpredictable things can happen. Do not use parentWindow or m_parentWindow inside the body of the Control constructor. If possible find a better, safer, way to do this. If not possible, document it with DO NOT USE messages to remind your future self or anyone else looking at the code not to use them.
Once this has been fixed you get to
MyWindow appWindow;
over in main. MyWindow's constructor requires a RECT you don't currently have a RECT to provide, so I'll stop here.
Move "window.h" from globals.h to controls.cpp. And put class Window; before class Controls { in controls.h. This is called forward declaration.
You even do not need window.h in controls.cpp, you can move it directly to your main.cpp.
I want to compile curl from source inside a Visual Studio project.
I get this error (and a lot more):
curl\src\tool_sdecls.h(67): error C2061: Syntax Error: Identifier'bool' (..\..\..\framework\libs\curl\src\tool_cb_dbg.c)
curl\src\tool_sdecls.h(68): error C2061: Syntax Error: Identifier'bool'is_cd_filename' (..\..\..\framework\libs\curl\src\tool_cb_dbg.c)
curl\src\tool_sdecls.h(68): error C2059: Syntax Error: ';' (..\..\..\framework\libs\curl\src\tool_cb_dbg.c)
The source of this file is:
65: struct OutStruct {
66: char *filename;
67: bool alloc_filename;
68: bool is_cd_filename;
69: bool s_isreg;
...
It looks like boolis not defined for some reason.
I tried defining HAVE_BOOL_T but nothing changed.
Any idea? Thanks
To solve the problem I added the folowing to curl_config.h
//for undefined bool error
#if _MSC_VER > 1700
#include <stdbool.h>
#else
#ifndef bool
typedef int bool;
#define false 0
#define true 1
#endif
#endif
//for warning C4005: 'POLLIN' : macro redefinition error
#define _WIN32_WINNT 0x0501
As the title says, I'm getting a compiler error in a VS2008 C++ program. I'm not sure how better to describe my problem than in code. The following compiles unless I uncomment the TEST line.
#include <windows.h>
#include <iostream>
using namespace std;
//#define TEST //<-- uncomment for error
#ifdef TEST
void test(void* interface)
{
return;
}
#endif
int main()
{
cout << "Hello World" << endl;
system("PAUSE");
return(0);
}
When uncommented I get the following errors:
1>main.cpp(7) : error C2332: 'struct' : missing tag name
1>main.cpp(7) : error C2144: syntax error : '<unnamed-tag>' should be preceded by ')'
1>main.cpp(7) : error C2144: syntax error : '<unnamed-tag>' should be preceded by ';'
1>main.cpp(7) : error C2059: syntax error : ')'
1>main.cpp(8) : warning C4094: untagged 'struct' declared no symbols
1>main.cpp(8) : error C2143: syntax error : missing ';' before '{'
1>main.cpp(8) : error C2447: '{' : missing function header (old-style formal list?)
This is unmanaged code, so I'm not sure what the issue with the word interface is. Is there any way to get this code to compile as is, or do I have to change every instance of the term interface to something else?
Thanks!
If your code needs to include Windows.h then you should avoid using the name interface as it's reserved for the use that the Windows SDK has reserved for it (essentially it's a synonym for the keyword struct). There are probably hacks to work around that problem (you could #undef interface after including the SDK headers), but you should probably avoid using that identifier.
The word interface is reserved by MSVC++, as it is a non-standard keyword added by Microsoft Compiler, which is used to define interface in MSVC++.
So use a different name for the parameter, something like this:
#ifdef TEST
void test(void* test_interface)
{
return;
}
#endif
I'm using Visual Studio 2008 Express Edition to compile the following code in a header file:
bool is_active(widget *w);
widget is defined earlier as,
typedef void widget;
The compiler complains with the error:
>c:\projects\engine\engine\engine.h(451) : error C2061: syntax error : identifier 'is_active'
1>c:\projects\engine\engine\engine.h(451) : error C2059: syntax error : ';'
1>c:\projects\engine\engine\engine.h(451) : error C2059: syntax error : 'type'
I get similar errors for all other functions returning bool.
NB. The following compiles fine:
void widget_activate_msg(widget *g, message *msg);
Why would this give a compiler error?
Some people have requested I post the code - here it is:
Line 449: widget * widget_new_from_resource(int resource_id);
Line 450: void widget_delete_one(widget *w);
Line 451: bool is_active(widget *w);
EDIT - this is now fixed:
#BatchyX commented below about whether I was using C or C++. What I didn't know was that Visual C++ 2008 will compile any file by default (but you can override this setting ) with the .c extension as C and those with .cpp as C++. ( the error was caused when compiling a .c file including "Engine.h" ).
Most likely, something above this line has a syntax error. Did you forget }s or ; after a class declaration ?
Also make sure you are using C++ and not C. C doesn't have a bool type. If you're using C, then use an int instead.
I'm guessing that it's not possible to typedef void. Why not use typdef void* WidgetPtr; and then bool is_active(WidgetPtr w);
EDIT: Having done some tests it's clear that void can be typedef'd and it can be part of the function signature as shown in the users code. So the only other solution is that whichever header has declared typedef void Widget is not included within the file that declares/defines the function or you're having a #def guard statement clash.