简体   繁体   English

Libtorch Linker 错误,Cmake 和 CLion

[英]Linker error with Libtorch, Cmake and CLion

I am just starting out with libtorch and seem to have run into a rather serious linker issue.我刚开始使用 libtorch,似乎遇到了一个相当严重的 linker 问题。 Previously, I was able to at least build other projects with torch (that others had created), but now that I've tried to create my own simple file, nothing seems to be building anymore.以前,我至少能够使用 torch(其他人创建的)构建其他项目,但现在我已经尝试创建自己的简单文件,似乎没有任何东西可以构建了。

I have manually installed the latest MacOS build in my root directory: /Users/jlenz/libtorch/share/cmake/Torch我已经在我的根目录中手动安装了最新的 MacOS 版本:/Users/jlenz/libtorch/share/cmake/Torch

I am using CLion and have the following CmakeLists.txt:我正在使用 CLion 并具有以下 CmakeLists.txt:

cmake_minimum_required(VERSION 3.23)
project(midi_plugin)

set(CMAKE_CXX_STANDARD 17)
add_executable(midi_plugin main.cpp)

set(CMAKE_PREFIX_PATH "~/libtorch/share/cmake")
find_package(Torch REQUIRED)

target_link_libraries(midi_plugin "${TORCH_LIBRARIES}")

One thing that is noticeable, although the cmake 'succesfully' builds, it displays this in the process:值得注意的一件事是,虽然 cmake“成功”构建,但它在过程中显示:

-- MKL_ARCH: intel64
-- MKL_ROOT /Users/jlenz/opt/miniconda3
-- MKL_LINK: dynamic
-- MKL_INTERFACE_FULL: intel_ilp64
-- MKL_THREADING: intel_thread
-- MKL_MPI: mpich

Once I try to build the project (which is just 'hello world' with torch included) I get the following error:一旦我尝试构建项目(这只是包含 torch 的“hello world”),我收到以下错误:

FAILED: midi_plugin 
: && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -mmacosx-version-min=12.5 -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/midi_plugin.dir/main.cpp.o -o midi_plugin  -Wl,-rpath,/Users/jlenz/libtorch/lib  /Users/jlenz/libtorch/lib/libc10.dylib  /Users/jlenz/libtorch/lib/libkineto.a  /Users/jlenz/libtorch/lib/libtorch.dylib  /Users/jlenz/libtorch/lib/libtorch_cpu.dylib  /Users/jlenz/libtorch/lib/libc10.dylib  -lmkl_intel_ilp64  -lmkl_core  -lmkl_intel_thread && :
ld: library not found for -lmkl_intel_ilp64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Would anyone know how to solve this?有人知道如何解决这个问题吗? I have tried addressing it with a colleague who has used libtorch quite a bit and he can't identify the issue either.我曾尝试与一位经常使用 libtorch 的同事一起解决这个问题,但他也无法确定问题所在。 Many thanks in advance.提前谢谢了。

Posting my solution here in case someone else runs into a similar issue.在这里发布我的解决方案以防其他人遇到类似问题。 It turns out the issue was with my brew installation of torch, which was being referenced implicitly.事实证明问题出在我的 brew 安装 torch 上,它被隐式引用了。 To fix it, all I had to do was:要修复它,我所要做的就是:

Brew install pytorch酿造安装 pytorch

It asked permission to overwrite some files that had issues, which I granted.它请求允许覆盖一些有问题的文件,我同意了。 Afterwards, all of my Torch projects are working perfectly.之后,我所有的 Torch 项目都运行良好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM