Adding boost header files gives compile time errors - c++

When i add the header file
#include <boost/fusion/adapted/struct/adapt_struct.hpp>
It gives couple of errors
error C2988: unrecognizable template declaration/definition
error C2143: syntax error: missing ';' before '<'
error C2913: explicit specialization; 'boost::type_of::id2type_impl' is not a specialization of a class template
error C2059: syntax error: '<'
error C2334: unexpected token(s) preceding '{'; skipping apparent function body
which point towards the line number 125 in typeof_impl.hpp file.

It's unclear what file you mean:
custom/boost_1_72_0/boost/typeof/typeof_impl.hpp
custom/boost_1_72_0/boost/typeof/msvc/typeof_impl.hpp
custom/boost_1_72_0/boost/typeof/dmc/typeof_impl.hpp
If you mean msvc/typeof_impl.hpp then most likely you have a preprocessor issue (where the source is mutated due to a redefined preprocessor token).
If there's no such file than #drescherjm's comment may be on point: there might be specific MSVC support missing in that version you're using.

After reading drescherjm , sehe's comments i changed some settings in the visual studio and when i changed platform Toolset from visual studio 2017 v(141) to visual studio 2015 v(140) , the program compiled sucessfully.

Related

Compile Errors When Including Boost 1.79.0 Bimap w/ Unreal 5

For over a year, I was using Boost's Bimap for the basis of an inventory system.
typedef boost::bimap<boost::bimaps::set_of<uint32>,
boost::bimaps::multiset_of<uint32>,
boost::bimaps::with_info<FItemDetails>> InventoryBimap;
After updating from Unreal 4 to Unreal 5, though, I made a few other changes. I moved from Boost 1.68.0 to 1.79.0. I moved from C++17 to C++20.
Edit: Sorry, I forgot to include I'm using Visual Studio 2022.
There are two sources for a bunch of compilation errors that prevent my game from compiling:
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(120): error C2988: unrecognizable template declaration/definition
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(127): note: see reference to class template instantiation 'boost::detail::ptr_to_expr<T,E>' being compiled
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(120): error C2059: syntax error: '<end Parse>'
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(120): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(120): error C2988: unrecognizable template declaration/definition
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(120): error C2059: syntax error: '->'
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(120): error C2238: unexpected token(s) preceding ';'
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(123): error C2988: unrecognizable template declaration/definition
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(123): error C2059: syntax error: '<end Parse>'
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(123): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
And then:
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\allocator_access.hpp(397): error C2988: unrecognizable template declaration/definition
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\allocator_access.hpp(407): note: see reference to class template instantiation 'boost::detail::alloc_has_allocate<A>' being compiled
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\allocator_access.hpp(397): error C2059: syntax error: '<end Parse>'
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\allocator_access.hpp(397): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\allocator_access.hpp(398): error C2988: unrecognizable template declaration/definition
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\allocator_access.hpp(398): error C2059: syntax error: '->'
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\allocator_access.hpp(400): error C2238: unexpected token(s) preceding ';'
The second error repeats for every single template inside of allocator_access.hpp.
The only short-term fix I've found so far is to comment out all of the bimap includes in my project.
I am currently unsure of how to proceed and was hoping someone had some insight into what may be going on.
So, I found an answer. I'll share it here so that everyone can know:
In pointer_traits.hpp, the template has two functions:
template<class O>
static auto check(int)->result<decltype(O::pointer_to(source()))>;
template<class>
static char check(long);
I suddenly noticed the name: "check".
"check" is an Unreal macro name that forces Unreal Engine to crash upon invocation (unless a debugger is attached). Therefore, the function invocation that looked normal was instead being interpreted as a call to Unreal's check macro and causing compilation failures.
So I had to rename "check" throughout boost to something else. This fixed the compile errors, and my inventory system has been working again.

Libtorch operator/syntax errors in Visual Studio

Hi recently I’ve installed Libtorch and I was able to use it in my new Visual Studio project without a problem. Currently I am trying to use Libtorch in an existing CUDA project. But I am having these strange errors when I include torch header and I couldn’t find any solution in the internet regarding to my problem. Does anyone have any idea what might be the cause of these errors?
Severity Code Description Project File Line Suppression State
Error C2833 'operator {' is not a recognized operator or type DepthSensing e:\research\libtorch\include\c10\util\flat_hash_map.h 1433
Error C2059 syntax error: 'newline' DepthSensing e:\research\libtorch\include\c10\util\flat_hash_map.h 1433
Error C2238 unexpected token(s) preceding ';' DepthSensing e:\research\libtorch\include\c10\util\flat_hash_map.h 1433
Error C2143 syntax error: missing ';' before 'const' DepthSensing e:\research\libtorch\include\c10\util\flat_hash_map.h 1433
Error C2833 'operator {' is not a recognized operator or type DepthSensing e:\research\libtorch\include\c10\util\order_preserving_flat_hash_map.h 1552
Error C2059 syntax error: 'newline' DepthSensing e:\research\libtorch\include\c10\util\order_preserving_flat_hash_map.h 1552
Error C2238 unexpected token(s) preceding ';' DepthSensing e:\research\libtorch\include\c10\util\order_preserving_flat_hash_map.h 1552
Error C2143 syntax error: missing ';' before 'const' DepthSensing e:\research\libtorch\include\c10\util\order_preserving_flat_hash_map.h 1552
Environment
Windows 10
CUDA 10.1
Visual Studio 2017
C++14
Thanks to #john I have realized that there was a macro in another library which has the same name as a typename in Libtorch library(which was a macro called V in my case), that’s why it was confused in compilation. I am sticking to this solution for now.
warning C4003: not enough actual parameters for macro 'max' - Visual Studio 2010 C++

Winbase.h doesn't support in creating DLL file

I would like to create a project use to call c++ method using c#. So, I need to create a dll file for all of my c++ function. But when i get an error in y sqlite source code such as "AreFileApisASNSI undeclared identifier". So, i import winbase.h which is part of the mingw-w64 runtime package to my visual studio 2012 express DLL project. After import the file, I get many errors such as below:-
error c4430: missing type specifier - int assumed. Note: C++ does not support default - int
error C2143: syntax error : missing ';' before '_stdcall'
error c1003 error count exceeds 100; stopping compilation
error c2061: syntax error: identifier ' WINBOOL'
error c2086: 'int_CRT_INLINE' : redefinition
error c2143: syntax error: missing ';' before ''
error C2146: syntax error : missing ';' before identifier 'LONGLONG'
error C2146: syntax error : missing ';' before identifier 'PVOID'
any solution for those error? please help!!
The documentation for the function has this header requirement:
WinBase.h (include Windows.h)
This is telling you that the function is declared in WinBase.h, but that you should include Windows.h which in turn will include WinBase.h. So, you need to change your include to
#include <Windows.h>
I also wonder why you are talking about mingw considering that your compiler is MSVC. That compiler ships with a comprehensive Windows SDK. Why would you be using an SDK from mingw?

VS 2012 template errors

I've been using this code to marshal strings in C++/CLI for a while now. Recently I've updated to VS 2012 RC to try it out. I really liked the simple design, but none of my projects containing clix.h could be compiled. It worked great in 2010... What could be the problem? Thank you for your answers!
Here is compiler output:
Warning C4346:
'clix::detail::IsManagedString::Result'dependent name is
not a type.
Error C2988: unrecognizable template declaration/definition
Error C2059: syntax error : '<'
Error C2039: 'Result' : is not a member of '`global namespace''
Error C2143: syntax error : missing ';' before '}'
The code block errors are in:
typename detail::Select<detail::IsManagedString<SourceType>::Result>::Type<
typename detail::StringTypeSelecter<encoding>::Type,
System::String ^>::Result marshalString(SourceType string) {
// Pass on the call to our nifty template routines
return detail::StringMarshaler<
detail::IsManagedString<SourceType>::Result ? detail::CxxFromNet : detail::NetFromCxx
>::marshal<encoding, SourceType>(string);
}
An example, source file:
#include "clix.h"
int main()
{
}
Clix header file can be found on this link.
You could have just posted the issue on my blog, it's not abandoned or anything :)
I happen to have Visual Studio 2012 RC installed and fixed the issue. You can find a new version of the clix header at the location you linked.
Background: it appears Microsofts new compiler is a bit picky regarding typedefs in nested templates whose parent templates are specialized on integer types. In any case, I found a method that works in both Visual C++ 2010 and Visual C++ 2012 RC.

Error building legacy code with VS 2005

Trying to build a legacy code in VS2005 and get errors in VC header files.
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2096) : error C2065: '_Sb' : undeclared identifier
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2176) : see reference to class template instantiation 'std::istreambuf_iterator<_Elem,_Traits>' being compiled
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2096) : error C3861: '_Strbuf': identifier not found
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2096) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2096) : error C2061: syntax error : identifier '_Sb'
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2097) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2098) : error C2143: syntax error : missing ';' before '{'
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2098) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
d:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(2176) : fatal error C1075: end of file found before the left brace '{' at 'd:\Compilers\Microsoft Visual Studio 8\VC\include\xutility(15)' was matched
I find the legacy code uses a vector and if I comment out those variables then the code compiles without any errors.
I get these errors even if I just include vector header without defining any variable.
All the files in the project are cpp files.
Do I need to add some preprocessor directives or compiler settings to get this working?
You may find that running the pre-process phase on one of the files might show if any macros are being expanded that conflict with vector or _Strbuf. See my post on how to do this:
Compiling a project (VS 2008) with the /p argument (preprocess to a file) doesn't compile
You probably need to remove some conflicting predefined macros. Leading underscores followed by uppercase letters, as in _Sb are reserved for the implementation. If you have that defined as something else, you'll get such errors. It's also possible the errors are because you've defined _Strbuf ot _Got.