Libtorch operator/syntax errors in Visual Studio - c++

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++

Related

Cannot compile Tomcat Native Library on Windows 10

Background -
I'm using Tomcat 9.0.8 as webserver for an Oracle APEX installation. I now need to make Tomcat FIPS-140 compliant. To this end, I'm trying to build the Tomcat Native Library, incorporating a FIPS-compliant OpenSSL. I've been working from these instructions:
https://www.ysofters.com/2017/07/25/building-and-using-fips-capable-openssl-in-apache-tomcat/
There are "official" Tomcat Native build instructions from Apache, but they require the use of Mladen's Custom Microsoft Compiler Toolkit Compilation, which AFAIK can't be built on Windows 10.
The build steps were as follows:
Build the OpenSSL FIPS Object Module
Build the FIPS capable OpenSSL
Build Apache Portable Runtime
Build Tomcat Native library
The last step is what failed, hence my question today.
Build Configuration -
Windows 10 SDK (10.0.19041.0)
Visual Studio Community 2019 Version 16.9.6
Build Errors -
According to the build docs, I needed to run the following nmake command:
nmake -f NMAKEMakefile WITH_APR=E:\native_build\deps\apr WITH_OPENSSL=E:\native_build\deps\openssl APR_DECLARE_STATIC=1 ENABLE_OCSP=1 WITH_FIPS=1
E:\native_build\deps contains compiled versions of Apache Portable Runtime and OpenSSL, built in the previous steps.
That nmake command results in these errors:
E:\Windows Kits\10\include\10.0.19041.0\um\fileapi.h(1105): error C2146: syntax error: missing ')' before identifier 'FileInformationClass'
E:\Windows Kits\10\include\10.0.19041.0\um\fileapi.h(1105): error C2081: 'FILE_INFO_BY_HANDLE_CLASS': name in formal parameter list illegal
E:\Windows Kits\10\include\10.0.19041.0\um\fileapi.h(1105): error C2061: syntax error: identifier 'FileInformationClass'
E:\Windows Kits\10\include\10.0.19041.0\um\fileapi.h(1105): error C2059: syntax error: ';'
E:\Windows Kits\10\include\10.0.19041.0\um\fileapi.h(1105): error C2059: syntax error: ','
E:\Windows Kits\10\include\10.0.19041.0\um\fileapi.h(1108): error C2059: syntax error: ')'
E:\Windows Kits\10\include\10.0.19041.0\um\winbase.h(9118): error C2146: syntax error: missing ')' before identifier 'FileInformationClass'
E:\Windows Kits\10\include\10.0.19041.0\um\winbase.h(9118): error C2081: 'FILE_INFO_BY_HANDLE_CLASS': name in formal parameter list illegal
E:\Windows Kits\10\include\10.0.19041.0\um\winbase.h(9118): error C2061: syntax error: identifier 'FileInformationClass'
E:\Windows Kits\10\include\10.0.19041.0\um\winbase.h(9118): error C2059: syntax error: ';'
E:\Windows Kits\10\include\10.0.19041.0\um\winbase.h(9118): error C2059: syntax error: ','
E:\Windows Kits\10\include\10.0.19041.0\um\winbase.h(9121): error C2059: syntax error: ')'
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\cl.EXE"' : return code '0x2'
I haven't been able to locate a solution to this, or even another instance of the problem, so hoping you folks have some insights.

Adding boost header files gives compile time errors

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.

Including <d3dkmthk.h> causes errors 'E0090 function returning function is not allowed'

In a x64 dll project on Visual Studio, adding this line :
#include <d3dkmthk.h>
gives me hundeds of errors like these :
Error (active) E0090 function returning function is not allowed
Error C2059 syntax error: '__cdecl'
Error C2143 syntax error: missing ';' before '__cdecl'
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int
The problem was caused by #define WIN32_LEAN_AND_MEAN, deleting this line solved the issue.

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?

Visual C++ compiler, errors compiling stdlib.h

I am trying to compile a file which requires functions included from cmath. I do not believe my code itself to be at fault for causing this error, I suspect the configuration (it persists even with all of the non-include code commented), but have no idea what is going wrong. I am compiling on a Windows host, 64 bit. Other than adding the masm build configuration, I don't believe I've changed any compile settings to non-default, and the problem persists after disabling masm, and by setting the target configuration to 32 bit. Here is my generated output:
1>...\VStudio\VC\include\stdlib.h(467): error C2062: type 'long' unexpected
1>...\VStudio\VC\include\stdlib.h(467): error C2062: type 'long' unexpected
1>...\VStudio\VC\include\stdlib.h(467): error C2059: syntax error : ')'
1>...\VStudio\VC\include\stdlib.h(468): error C2143: syntax error : missing ';' before '{'
1>...\VStudio\VC\include\stdlib.h(468): error C2447: '{' : missing function header (old-style formal list?)
1>...\VStudio\VC\include\stdlib.h(471): error C2062: type '__int64' unexpected
1>...\VStudio\VC\include\stdlib.h(471): error C2062: type '__int64' unexpected
1>...\VStudio\VC\include\stdlib.h(471): error C2059: syntax error : ')'
1>...\VStudio\VC\include\stdlib.h(472): error C2143: syntax error : missing ';' before '{'
1>...\VStudio\VC\include\stdlib.h(472): error C2447: '{' : missing function header (old-style formal list?)
Any help would be greatly appreciated.
Edit:
I have found the troublesome line. Contrary to my expectation, the error does occur in the code, and is the fault of a line inherited from a previous version:
#define abs(a) ((a)<0? -(a):(a))
is responsible for my problems.
Next time, #include system headers before any of your own code. That way your macros can't mess with the system headers and lead you astray.