OpenCL compiling with C++ bindings - c++

I'm trying to compile the cl.hpp from Khronos Groups with VS2010, and I have the following message:
1>c:\users\facundo\documents\visual studio 2010\projects\opencl\opencl\cl.hpp(4757): error C2039: 'resize' : it is not a member of 'cl::vector<T>'
1> with
1> [
1> T=cl_context_properties
1> ]
How to compile C++/OpenCL projects on VS2010 correctly?

cl::vector<> has been deprecated.
By default cl.hpp should pick std::vector<> as the default vector class.
Maybe you defined __NO_STD_VECTOR or you are using cl::vector<> yourself?

Related

Google test fails to build with Intel 19 and Visual Studio c++ 19

I'm trying to embed Google Test in my project. I am using:
Project Type: Visual Studio 16 2019
Toolset: Intel C++ Compiler 19.0
Architecture: 64 bits
CMake version: 3.16.1
I am following the instructions of Google Test readme
I am using the master branch (version 1.10) of Gtest repository.
Cmake runs ok, and Visual Studio solution is generated. But when building it, cmock and gtest projects fail to build with the following errors:
1>gtest-all.cc
1>Error #2586: \'operator=\' : decorated name length exceeded, name was truncated
1>gmock-all.cc
1>C:\Users\saa4\Downloads\googletest-master\googlemock\include\gmock/gmock-actions.h(816): message #411: class template "testing::internal::InvokeMethodAction<Class, MethodPtr>" defines no constructor to initialize the following:
1> const member "testing::internal::InvokeMethodAction<Class, MethodPtr>::obj_ptr"
1> const member "testing::internal::InvokeMethodAction<Class, MethodPtr>::method_ptr"
1> struct InvokeMethodAction {
1> ^
1>
1>C:\Users\saa4\Downloads\googletest-master\googlemock\include\gmock/gmock-actions.h(845): message #411: class template "testing::internal::InvokeMethodWithoutArgsAction<Class, MethodPtr>" defines no constructor to initialize the following:
1> const member "testing::internal::InvokeMethodWithoutArgsAction<Class, MethodPtr>::obj_ptr"
1> const member "testing::internal::InvokeMethodWithoutArgsAction<Class, MethodPtr>::method_ptr"
1> struct InvokeMethodWithoutArgsAction {
1> ^
When setting the compiler to Visual C++ it builds normally. Do I need te set any extra configuration parameter for Intel?

emplace_back different definitions

I'm using emplace_back function in a cpp project in visual studio and it works correctly. Visual studio shows following definition for it:
void std::vector<std::string>::emplace_back<CHAR(&)[1]>(CHAR(&_Val)[1])
Then, I'm going to move my cpp project files to a MFC project and use them in a dialog based app. When I moved codes to MFC project, emplace_back definition has changed to:
void std::vector<std::string>::emplace_back<WCHAR(&)[1]>(WCHAR(&_Val)[1])
And it leads to C2664 Error in xmemory0 after build:
Error C2664
std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(const std::basic_string<char, std::char_traits<char>, std::allocator<char>> &)':
cannot convert argument 1 from 'WCHAR [1]' to 'std::initializer_list<_Elem>'
And in output it says:
note: see reference to function template instantiation 'void std::vector<std::string,std::allocator<_Ty>>::emplace_back<WCHAR(&)[1]>(WCHAR (&)[1])' being compiled
1> with
1> [
1> _Ty=std::string
1> ]
How can I deal with such problems? Is there any option in properties of Visual Studio Project to correct?
Thanks

Cannot include ppltasks.h C++11 header in VS2012

While playing around with the C++11 features of Visual Studio 2012, I encountered strange errors when including the "ppltasks.h" header file (which is included via the "future" header file:
Main.cpp
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\ppltasks.h(3306): error C2512: 'Concurrency::details::_PPLTaskHandle<Concurrency::details::_NormalizeVoidToUnitType<void>::_Type,Concurrency::task<std::pair<Concurrency::details::_Unit_type,Concurrency::details::_CancellationTokenState *>>::_ContinuationTaskHandle<_InternalReturnType,_TaskType,_Function,Concurrency::details::_FunctionTypeTraits<_Function,_ReturnType>::_Takes_task,Concurrency::details::_TaskTypeTraits<void,false>::_AsyncKind>,Concurrency::details::_ContinuationTaskHandleBase>' : no appropriate default constructor available
1> with
1> [
1> _InternalReturnType=std::pair<Concurrency::details::_Unit_type,Concurrency::details::_CancellationTokenState *>
1> , _Function=Concurrency::||::<lambda_06496b162c644bf2f90c850c3dfa7d5c>
1> , _ReturnType=std::pair<Concurrency::details::_Unit_type,Concurrency::details::_CancellationTokenState *>
1> ]
The error is longer, but you get the gist of it. Has anybody else encountered such an error message from simply including the "future" header, and is there a known solution? Thanks.
Turns out that the Project Settings must have language extensions enabled for the header to compile correctly (as of now).

Reading and writing size_t to a binary file

Disclaimer: it's just another task for beginner so I'm good with the fact that on different compilers and on different architectures I may get different (incompatible) binaries as a result. So it's ok that it will only work only on this particular machine.
I'm writing and reading size_t from a binary file. Writing looks like:
std::string result;
result.append((char *)&block_size_, sizeof(block_size_));
and soon after that result is written to a file.
But when I read it in a same way:
map_binary.copy((char *)&block_size_, sizeof(block_size_), offset);
I get a warning
warning C4996: 'std::basic_string<_Elem,_Traits,_Alloc>::copy': 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> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Alloc=std::allocator<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstring(1777) : see declaration of 'std::basic_string<_Elem,_Traits,_Alloc>::copy'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Alloc=std::allocator<char>
1> ]
I cannot get why this code is unsafe and looking for a solution other than pretending there is no issues at all (using the -D_SCL_SECURE_NO_WARNINGS).
So, what am I missing?
PS: right now I'm learning C++ using only standard library, so solutions that use boost or something else are unacceptable.
You're not missing anything. VC++ is very keen to warn you if you copy anything to a pointer. In this case there is no guarantee that you will get the size of destination correct. After all you might write something like this map_binary.copy((char *)&block_size_, 4, offset); and then find your code fails with a 64-bit compiler.
If you're happy with your ability to avoid this kind of error then disable or ignore the warning.

Using STL port in VS2008

I am working on porting our C++ code from eVC 4.0 to Visual Studio 2008. Our target is Windows Mobile 6.1 and we are using the Windows Mobile 6.0 SDK for our app.
Our code used stl port when compiled in eVC 4 and we would like to continue to use stl port if at all possible.
Does anyone know what steps are necessary to incorporate STL port (5.2.1) in our application. We have set the include directories in the solution (as we did for the eVC 4.0 project), but we are seeing the errors (below) any time we try to use list push_back or vector insert commands with our own classes (below is the error with our class "TriangleBufferElement"). These commands do seem to work with native types like int, double, etc.
We have ensured all classes have the proper contructors, copy constructors, assignment operators, and comparison operators and all appear to be correct.
Any ideas?
C:\Program Files\Windows CE Tools\stlport\stl/_construct.h(119) : error C2665: 'operator new' : none of the 2 overloads could convert all the argument types
1> C:\Program Files\Windows Mobile 6 SDK\PocketPC\include\../../../Windows Mobile 6 SDK\PocketPC\Include\Armv4i/new(61): could be 'void *operator new(unsigned int,const std::nothrow_t &) throw()'
1> while trying to match the argument list '(unsigned int, TriangleBufferElement *)'
1> C:\Program Files\Windows CE Tools\stlport\stl/_construct.h(134) : see reference to function template instantiation 'void stlp_std::_Copy_Construct_aux<_Tp>(_Tp *,const _Tp &,const stlp_std::__false_type &)' being compiled
1> with
1> [
1> _Tp=TriangleBufferElement
1> ]
1> C:\Program Files\Windows CE Tools\stlport\stl/_vector.h(381) : see reference to function template instantiation 'void stlp_std::_Copy_Construct<_Tp>(_Tp *,const _Tp &)' being compiled
1> with
1> [
1> _Tp=TriangleBufferElement
1> ]
1> C:\Program Files\Windows CE Tools\stlport\stl/_vector.h(376) : while compiling class template member function 'void stlp_std::vector<_Tp>::push_back(const _Tp &)'
1> with
1> [
1> _Tp=TriangleBufferElement
1> ]
1> c:\srcdevbranch\pointlib\dtmconverter\dtm\dtmreader\.\trianglebuffer.h(47) : see reference to class template instantiation 'stlp_std::vector<_Tp>' being compiled
1> with
1> [
1> _Tp=TriangleBufferElement
1> ]
Some links you probably should see (if not seen already):
STLPort Notes:
You may experience problems with default SGI node allocator. I had no such problems, though. Default node allocator is quite fast, so I wouldn't recommend disabling it without serious reason. However, if it causes problems, define _STLP_USE_MALLOC or _STLP_USE_NEWALLOC to get bare malloc()-based or new()-based default allocator.
Though this post says it has not yet been ported to VS2008.
Have you reconfigured STLPort for the new compiler environment? Visual Studio 2008 is quite different from the old eVC++ compiler.
Try:
configure evc9
In my case, this was due to __PLACEMENT_NEW_INLINE defined