I have the following lines in a rather large file:
#include <sha.h>
#include <hex.h>
Which, when compiled, throws this compiler error:
1>d:\work\app\tools\cryptopp\algparam.h(322): error C2061: syntax error : identifier 'buffer'
1> d:\work\app\tools\cryptopp\algparam.h(321) : while compiling class template member function 'void CryptoPP::AlgorithmParametersTemplate<T>::MoveInto(void *) const'
1> with
1> [
1> T=bool
1> ]
1> d:\work\app\tools\cryptopp\algparam.h(329) : see reference to class template instantiation 'CryptoPP::AlgorithmParametersTemplate<T>' being compiled
1> with
1> [
1> T=bool
1> ]
I'm pretty sure I'm forgetting something, but I'm not sure what. If I don't include hex.h, I don't have any problems and I get a SHA256 hash just fine, but when I do include hex.h, the error pops up.
Edit
In case anyone wonders, from algparam.h of Crypto++ toolkit:
void MoveInto(void *buffer) const //<=== line 320
{
AlgorithmParametersTemplate<T>* p = new(buffer)
AlgorithmParametersTemplate<T>(*this);
}
CRYPTOPP_DLL_TEMPLATE_CLASS AlgorithmParametersTemplate<bool>; // <== line 329
Edit: Removed unrelated code
I fixed the problem by temporarily undefining new, which was defined as a macro to some extra debugging code.
#pragma push_macro("new")
#undef new
/* #includes for Crypto++ go here */
#pragma pop_macro("new")
If you're including Crypto++ in a Visual Studio project with MFC support, this error might be caused by this line:
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
Make sure to remove it or comment it out.
Related
I'm working off of a sample c++ that I was given, and I'm trying to add threading to the program.
If anywhere in the program I add the following:
#include <thread>
void someFunction () {
std::thread t([]() {std::cout << "Hello" << std::endl; });
}
It fails to compile with the error:
1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thread(48): error C3083: 'std': the symbol to the left of a '::' must be a type
1> C:\Users\Dennis Jeong\Documents\Stanford\CS148\cs148-raytracer\common\RayTracer.cpp(20): note: see reference to function template instantiation 'std::thread::thread<RayTracer::Run::<lambda_d2fd5ec539e104442fc3c5987873ac7f>,,void>(_Fn &&)' being compiled
1> with
1> [
1> _Fn=RayTracer::Run::<lambda_d2fd5ec539e104442fc3c5987873ac7f>
1> ]
However, if I create a new c++ project in visual studio, this works.
Where could the error possibly be?
If it is helpful, the cmake file is here:
https://gist.github.com/w0nche0l/aef2a112b596f489705441f429e725b5
EDIT: additionally, I'm sure that it is not the lambda syntax that is causing this error, because I can create and run lambdas without threads fine.
I'm very new to C++/VS and might missing something in the code/configuration of my project.
In my solution I have 2 projects:
first is NTL which I downloaded from https://bitbucket.org/ben_key/ntl, and compiled to a static library NTL.lib.
a 'test' project in which: (1) I added the header files by specifying their directory in the properties->C++->Additional Include Files, (2) in the properties->Linker->Input->Additional Dependencies I added "NTL.lib" (3)copied the NTL.lib file to be in the same directory as the main cpp file of the 'test' project.
My cpp only contains:
#include <NTL/GF2X.h>
int main() {
GF2X P;
return 1;
}
The build gives the output:
1>------ Build started: Project: test, Configuration: Release Win32 ------
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppBuild.targets(388,5): warning MSB8028: The intermediate directory (Release\) contains files shared from another project (ntl-test.vcxproj). This can lead to incorrect clean and rebuild behavior.
1> QuickTest.cpp
1>..\tests\QuickTest.cpp(43): warning C4101: 'n' : unreferenced local variable
1>D:\studies\Thesis\NTL-Ben-Key\Include\NTL/vector.h(79): warning C4291: 'void *operator new(size_t,_ntl_vector_placement)' : no matching operator delete found; memory will not be freed if initialization throws an exception
1> D:\studies\Thesis\NTL-Ben-Key\Include\NTL/vector.h(36) : see declaration of 'operator new'
1> D:\studies\Thesis\NTL-Ben-Key\Include\NTL/vector.h(319) : see reference to function template instantiation 'void NTL::BlockConstruct<T>(T *,long)' being compiled
1> with
1> [
1> T=NTL::zz_p
1> ]
1> D:\studies\Thesis\NTL-Ben-Key\Include\NTL/vector.h(291) : while compiling class template member function 'void NTL::Vec<NTL::zz_p>::DoSetLength(long)'
1> D:\studies\Thesis\NTL-Ben-Key\Include\NTL/vector.h(115) : see reference to function template instantiation 'void NTL::Vec<NTL::zz_p>::DoSetLength(long)' being compiled
1> D:\studies\Thesis\NTL-Ben-Key\Include\NTL/vec_lzz_p.h(14) : see reference to class template instantiation 'NTL::Vec<NTL::zz_p>' being compiled
1> MyTest.cpp
1>MyTest.cpp(4): error C2065: 'GF2X' : undeclared identifier
1>MyTest.cpp(4): error C2146: syntax error : missing ';' before identifier 'P'
1>MyTest.cpp(4): error C2065: 'P' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
It is really a simple thing and I didn't figured out what I'm missing.
From NTL/include/NTL/ tools.h:
#define NTL_NAMESPACE NTL
#define NTL_OPEN_NNS namespace NTL_NAMESPACE {
#define NTL_CLOSE_NNS }
So when the preprocessor encounters NTL_OPEN_NNS, as is the case in the include file GF2X.h, it expands it to namespace NTL meaning the GF2X class is declared insided the namespace NTL. In order to use it you need to fully qualify it as NTL::GF2X or use using namespace NTL for discussion about which one look here for example.
Likewise at the end of GF2X.h there is a closing bracket after expanding NTL_CLOSE_NNS
I'm using visual studio 2012 and I isolated a problem in my code to this, but I can't solve it. When running it in release mode it works perfect, but I get an error if I run it in debug.
The code is:
#include "stdafx.h"
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
typedef boost::numeric::ublas::matrix<double> BMT;
BMT fun()
{
BMT mym;
mym.resize(3,3);
for(int i = 0; i<9;++i) mym(i/3,i%3)=i;
std::cout << mym << std::endl;
return mym;
}
int main(int argc, char* argv[])
{
fun();
//closing message
std::cout<<std::endl<<"press enter to exit."<<std::endl;
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
}
and the error in debug is the following:
1>------ Build started: Project: myproject, Configuration: Debug x64 ------
1> myapp.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xmemory(348): error C4996: 'std::_Uninitialized_copy0': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
1> C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xmemory(333) : see declaration of 'std::_Uninitialized_copy0'
1> C:\thirdparty\vs2012\x64\boost_1_53_0\boost/numeric/ublas/storage.hpp(94) : see reference to function template instantiation '_FwdIt std::uninitialized_copy<const double*,double*>(_InIt,_InIt,_FwdIt)' being compiled
1> with
1> [
1> _FwdIt=double *,
1> _InIt=const double *
1> ]
1> C:\thirdparty\vs2012\x64\boost_1_53_0\boost/numeric/ublas/storage.hpp(89) : while compiling class template member function 'boost::numeric::ublas::unbounded_array<T>::unbounded_array(const boost::numeric::ublas::unbounded_array<T> &)'
1> with
1> [
1> T=double
1> ]
1> C:\thirdparty\vs2012\x64\boost_1_53_0\boost/numeric/ublas/matrix.hpp(160) : see reference to function template instantiation 'boost::numeric::ublas::unbounded_array<T>::unbounded_array(const boost::numeric::ublas::unbounded_array<T> &)' being compiled
1> with
1> [
1> T=double
1> ]
1> C:\thirdparty\vs2012\x64\boost_1_53_0\boost/numeric/ublas/matrix.hpp(100) : see reference to class template instantiation 'boost::numeric::ublas::unbounded_array<T>' being compiled
1> with
1> [
1> T=double
1> ]
1> junkApp1.cpp(10) : see reference to class template instantiation 'boost::numeric::ublas::matrix<T>' being compiled
1> with
1> [
1> T=double
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Do you know what can the problem be?
I was having a similar issue using ublas.
I am not sure what the cause might be but I suppose it's got to do with ublas' copy on write / copy on demand optimizations. Would it be an option to just use the define -D_SCL_SECURE_NO_WARNINGS and be done with it? I have that set globally as I consider 90% of those warnings OS specifc BS anyway.
The problem is that you are compiling with warnings treated as errors.
EDIT: Microsoft has decided that certain parts of C++ (and C) are deprecated, and the compiler reports use of those parts as errors unless _SCL_SECURE_NO_WARNINGS (respectively _CRT_SECURE_NO_WARNINGS) is defined.
I got this warning message.. but i dont know what/where the problem is..!
includes
#pragma warning(push)
#pragma warning(disable:4996)
#include <boost/archive/iterators/base64_from_binary.hpp>
#include <boost/archive/iterators/insert_linebreaks.hpp>
#include <boost/archive/iterators/transform_width.hpp>
#include <boost/archive/iterators/ostream_iterator.hpp>
#pragma warning(pop)
and the warning
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(2227): warning C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(2212): Siehe Deklaration von 'std::_Copy_impl'
1> c:\users\perlig\documents\visual studio 2010\projects\restmanager\restmanager\**http.cpp(257)**: Siehe Verweis auf die Instanziierung der gerade kompilierten Funktions-template "_OutIt std::copy<boost::archive::iterators::insert_linebreaks<Base,N>,boost::archive::iterators::ostream_iterator<Elem>>(_InIt,_InIt,_OutIt)".
1> with
1> [
1> _OutIt=boost::archive::iterators::ostream_iterator<char>,
1> Base=boost::archive::iterators::base64_from_binary<boost::archive::iterators::transform_width<const char *,6,8>>,
1> N=76,
1> Elem=char,
1> _InIt=boost::archive::iterators::insert_linebreaks<boost::archive::iterators::base64_from_binary<boost::archive::iterators::transform_width<const char *,6,8>>,76>
1> ]
the code occur in line 257 as the warning message says. but i´m not able to fix it because i not know what is wrong..
string data contains a "user:password" string for basic auth via http.
http.cpp(257):
// typdef, prepare
using namespace boost::archive::iterators;
stringstream os;
typedef
insert_linebreaks< // insert line breaks every 72 characters
base64_from_binary< // convert binary values ot base64 characters
transform_width< // retrieve 6 bit integers from a sequence of 8 bit bytes
const char *,
6,
8
>
>
,76
>
base64_text; // compose all the above operations in to a new iterator
// encrypt
#pragma warning(push)
#pragma warning(disable:4996)
copy( //<<<<<------ LINE 257
base64_text(data.c_str()),
base64_text(data.c_str() + data.size()),
boost::archive::iterators::ostream_iterator<char>(os)
);
#pragma warning(pop)
anybody got any idea?
I think you know what is the meaning of the warning but first I describe the warning and then say what to do to get rid of it. Microsoft implemented a new security enabled set of function in its CRT, STL, MFC, ... and mark old version of those functions as deprecated to provide a hint for you that you should migrate to new secure version. so it say std::copy is unsafe!! how? as follow:
char storage[ 10 ], *p = storage;
std::copy( std::istream_iterator<int>(std::cin), std::istream_iterator<int>(), p );
Now what will happened if user input more than 10 int? the memory will be overwritten and you corrupted your memory.
Using boost::archive::iterators::ostream_iterator is perfectly safe but since it does not follow the design of safe iterators in MSVC it will considered as unsafe.
Now you should either disable this warning by -D_SCL_SECURE_NO_WARNINGS to cl input flags or add a pragma to disable this warning( as you do ), but why pragma don't work?
the reason is obvious, this pragma work on scope and the scope that you use pragma on it have nothing wrong, you must guard xutility with this pragma and every thing will work as expected.
I have created Dialog Based application in MFC (VS 2008).When I do "#include" in Dlg.cpp it showing following error.
Is Some Component is missing in the VS 2008 Installation
c:\program files (x86)\microsoft visual studio 9.0\vc\include\xmemory(43) :
error C2665: 'operator new' : none of the 5 overloads could convert all the argument types
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\new.h(85): could be 'void *operator new(size_t,const std::nothrow_t &) throw()'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\new.h(93): or 'void *operator new(size_t,void *)'
1> while trying to match the argument list '(const char [70], int)'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xmemory(145) : see reference to function template instantiation '_Ty *std::_Allocate<char>(size_t,_Ty *)' being compiled
1> with
1> [
1> _Ty=char
1> ]
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xmemory(144) : while compiling class template member function 'char *std::allocator<_Ty>::allocate(std::allocator<_Ty>::size_type)'
1> with
1> [
1> _Ty=char
1> ]
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\xstring(2216) : see reference to class template instantiation 'std::allocator<_Ty>' being compiled
1> with
1> [
1> _Ty=char
1> ]
1>Build log was saved at "file://c:\Users\Public\Documents\Proj\STL1\STL1\Debug\BuildLog.htm"
1>STL1 - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Any STL includes in your MFC project should be included prior to the definition of DEBUG_NEW. This was a problem in the past (no longer seems to be, as I cannot reproduce it in VS 2010).
// myfile.cpp
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// This will cause the error
#include <vector>
Whereas
// myfile.cpp
// will work OK
#include <vector>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
DEBUG_NEW is a microsoft specific extension that helps to find memory leaks in debug versions of the application. It can be very useful in certain cases.
It's defined in afx.h as:
void* AFX_CDECL operator new(size_t nSize, LPCSTR lpszFileName, int nLine);
#define DEBUG_NEW new(THIS_FILE, __LINE__)`
It's helps to provide tracking of memory allocated and when a leak is detected will give you the file and line number where the allocation took place.