LibTorch with CMake via Eclipse in Windows:Terminated exit value 390

LibTorch with CMake via Eclipse in Windows:Terminated exit value 390

我使用 cmake4eclipse 在 Windows 10 中构建了稳定的 torch C++ 1.0 版。基本上,我有以下 CMakeLists.txt 来构建 mnist 示例:

cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(mnist)

set(CMAKE_PREFIX_PATH "C:/rl/libtorch/share/cmake/Torch")
set(Torch_DIR "C:/rl/libtorch")

find_package(Torch REQUIRED)

option(DOWNLOAD_MNIST "Download the MNIST dataset from the internet" ON)
if (DOWNLOAD_MNIST)
  message(STATUS "Downloading MNIST dataset")
  execute_process(
    COMMAND python ${CMAKE_CURRENT_LIST_DIR}/download_mnist.py
      -d ${CMAKE_BINARY_DIR}/data
    ERROR_VARIABLE DOWNLOAD_ERROR)
  if (DOWNLOAD_ERROR)
    message(FATAL_ERROR "Error downloading MNIST dataset: ${DOWNLOAD_ERROR}")
  endif()
endif()

set(CMAKE_BUILD_TYPE Debug) 
add_executable(mnist mnist.cpp)
target_compile_features(mnist PUBLIC cxx_range_for)
set_property(TARGET mnist PROPERTY CXX_STANDARD 14)
target_link_libraries(mnist ${TORCH_LIBRARIES})

然后,我将它与 mnist.cppdownload_mnist.py 文件一起加载到一个文件夹中,并在 eclipse IDE for C/C++ 版本 2018-09 (4.9.0) 中启动一个项目。在project_properties->C/C++ Build->Tool Chain Editor中,我设置了CMake Builder (GNU Make)和selectMinGW GCC。然后,在 project_properties->C/C++ General->Preprocessor Include Paths Macros etc.->Providers I select CMAKE_EXPORT_COMPILE_COMMANDS Parser [Shared] and将其向上移动,正如所解释的那样 here

然后,我可以编译 mnist 项目而不会出现任何错误。但是,当我 运行 它得到 <terminated> (exit value 390) a.exe [some address]。我试图调试此代码以找出问题所在,但我看不到调试屏幕,而是得到:

运行debug模式进行到最后,同样报错。 我可以 运行 mnist.cpp in Linux 没有任何问题,尽管我使用 cmake -G "Eclipse CDT4 - Unix Makefiles" ./ 创建一个 eclipse 项目。我不知道如何在 Windows 中使用 cmake -G "Eclipse CDT4 - Unix Makefiles" ./ 而我使用了 cmake4eclipse 我相信我错过了处理 [=53= 中的 CMakeLists.txt 文件的步骤].感谢任何帮助或评论。

谢谢, 阿夫欣

我在 torch git 中问过同样的问题,今天我得到了答案。目前看来,我们将无法通过 Eclipse 和 MinGw 运行 Libtorch。这是我从 torch git 页面得到的答案:

"I don't think you could build that with MinGW because the code is written in c++ and MinGW is not abi-compatible with MSVC. So I think you may need to compile with MSVC. And also in MSVC, the configuration debug and release could not be mixed. So you will have to choose Release as we only provide library with the Release configuration."

查看更多详细信息: https://github.com/pytorch/pytorch/issues/15711