c++ - Visual Studio 中的 Libtorch 运算符/语法错误

标签 c++ visual-studio pytorch libtorch

您好,最近我安装了 Libtorch,并且可以在我的新 Visual Studio 项目中毫无问题地使用它。目前我正在尝试在现有的 CUDA 项目中使用 Libtorch。但是当我包含 torch 头时,我遇到了这些奇怪的错误,并且我在互联网上找不到有关我的问题的任何解决方案。有谁知道这些错误的原因可能是什么?

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

环境

  • Windows 10
  • CUDA 10.1
  • Visual Studio 2017
  • C++14

最佳答案

感谢@john,我意识到另一个库中有一个与 Libtorch 库中的类型名称同名的宏(在我的例子中是一个名为 V 的宏),这就是为什么编译时很困惑。我现在坚持使用这个解决方案。

warning C4003: not enough actual parameters for macro 'max' - Visual Studio 2010 C++

关于c++ - Visual Studio 中的 Libtorch 运算符/语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61029916/

相关文章:

python - Pytorch 运行时错误 : size mismatch, m1 : [1 x 7744], m2:[400 x 120]

c++ - 在 CPLEX 中自动创建 MILP 模型

c++ - vector::emplace_back 与 shared_ptr 的用法

c++ - Void 与 Int 输出参数签名

c++ - Visual C++ 6.0 中查找源文件的预设位置

python - 将 Python 对象传递给 C 然后再返回

c++ - "new int * **[10]"是做什么的?

visual-studio - 与 Visual Studio 一起使用 Meld

c# - 为什么 Microsoft Visual C# 2008 Express Edition 调试器随机退出?

python - 多 GPU 训练中的损失函数 (PyTorch)