1

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
theycallmefm
  • 67
  • 1
  • 8
  • 1
    Do you have any macros defined which could be affecting the compilation of the libtorch headers? What happens if you include the libtorch eaders as the very first headers in your code? – john Apr 04 '20 at 14:57
  • You were right @john ! There was a macro in another library which has same name as a typename in Libtorch library, that's why it is confused in compilation. Is this approach suitable in my case? I've tried this it works now but I am not sure if this is the right way. https://stackoverflow.com/questions/6884093/warning-c4003-not-enough-actual-parameters-for-macro-max-visual-studio-2010 – theycallmefm Apr 04 '20 at 16:00
  • 1
    There's no perfect solution here, the two headers are basically incompatible. If what you are doing works for you then go for it. Just remember to add some comments to your code to explain why you have done what you've done. – john Apr 04 '20 at 16:19

1 Answers1

2

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

theycallmefm
  • 67
  • 1
  • 8