【发布时间】:2019-05-18 01:28:50
【问题描述】:
我正在尝试通过调用 torch/torch.h 的 CMake 创建一个 Eclipse C++ 项目。我运行cmake -G "Eclipse CDT4 - Unix Makefiles" ./ 来创建一个Eclipse 项目,但我得到了这个错误:
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Could not determine Eclipse version, assuming at least 3.6 (Helios). Adjust CMAKE_ECLIPSE_VERSION if this is wrong.
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:10 (find_package):
By not providing "FindTorch.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Torch", but
CMake did not find one.
Could not find a package configuration file provided by "Torch" with any of
the following names:
TorchConfig.cmake
torch-config.cmake
Add the installation prefix of "Torch" to CMAKE_PREFIX_PATH or set
"Torch_DIR" to a directory containing one of the above files. If "Torch"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
其中CMakeLists.txt所在的当前目录有:
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(test)
find_package(Torch REQUIRED)
add_executable(test test.cpp)
target_link_libraries(test "${TORCH_LIBRARIES}")
set_property(TARGET test PROPERTY CXX_STANDARD 11)
显然,它找不到TorchConfig.cmake 和torch-config.cmake 文件;不过,我在/home/afshin/libtorch/share/cmake/Torch 中有 TorchConfig.cmake。我通过测试每个将相应的路径添加到CMakeLists.txt文件中:
set(CMAKE_MODULE_PATH "/home/afshin/libtorch/share/cmake/Torch;${CMAKE_MODULE_PATH}")
set(CMAKE_MODULE_PATH "/home/afshin/libtorch/share/cmake;${CMAKE_MODULE_PATH}")
set(CMAKE_MODULE_PATH "/home/afshin/libtorch;${CMAKE_MODULE_PATH}")
set(Torch_DIR "/home/afshin/libtorch;${Torch_DIR}")
set(Torch_DIR "/home/afshin/libtorch/share/cmake/Torch;${Torch_DIR}")
set(Torch_DIR "/home/afshin/libtorch/share/cmake;${Torch_DIR}")
set(DCMAKE_PREFIX_PATH "/home/afshin/libtorch/share/cmake/Torch;${DCMAKE_PREFIX_PATH}")
set(DCMAKE_PREFIX_PATH "/home/afshin/libtorch/share/cmake;${DCMAKE_PREFIX_PATH}")
set(DCMAKE_PREFIX_PATH "/home/afshin/libtorch;${DCMAKE_PREFIX_PATH}")
但是,它没有帮助,我仍然得到同样的错误。 我感谢任何帮助或 cmets。
我也尝试了 cmake-gui,我得到了同样的错误:
谢谢, 阿夫辛
【问题讨论】:
-
那么这个文件在哪里?
-
你能运行 cmake-gui 并检查平面路径是否被拾取?
-
@MatthieuBrucher 它在我的 Eclipse 工作区的一个新目录下: ls eclipse-workspace/test_cmake/ CMakeCache.txt CMakeFiles CMakeLists.txt src
-
CMake 正在寻找的 .cmake 文件。
-
嗯,您的问题帖子恰恰相反:“显然,它找不到
TorchConfig.cmake和torch-config.cmake文件。”。您能否更新问题帖子以反映实际情况?如果你有那个文件,在缓存中设置Torch_DIR应该可以工作。我不知道为什么没有(根据屏幕截图,您已经尝试过但失败了)。请注意,Torch_DIR本质上是 single-value 变量,将其设置为列表将不起作用。您也可以尝试将变量CMAKE_PREFIX_PATH设置为/home/afshin/libtorch。