在Mac上的约会Linker LD
我正在尝试使用指令来编译一个示例Pytroch C ++项目:
httpps://pytorch.org/cppdocs/ installing.html
当我到达通话点时:
cmake -dcmake_prefix_path =/absolute/path/to/libtorch .. CMAKE-建造。 - config发行版
我会发现一个错误:
ld: unknown option: --no-as-needed
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [BLOCK_READER] Error 1
make[1]: *** [CMakeFiles/BLOCK_READER.dir/all] Error 2
make: *** [all] Error 2
似乎问题是链接器不了解选项 - 不需要的
。
经过一些研究,它看起来像是链接器的新版本支持此选项,但不支持我拥有的版本。
因此,我的问题是如何将链接器更新为支持此选项的版本?
我在Apple M1(Bigsur)上。
这是我的理解是LD是GCC的一部分,所以我可以更新GCC吗?
顺便说一句,这是我的cmake cmakelists.txt
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(block_reader)
# Setup Torch
set(CMAKE_CXX_COMPILER "/usr/bin/g++" CACHE STRING "C++ compiler" FORCE)
set(CMAKE_LINKER "/usr/bin/ld" CACHE STRING "" FORCE)
set(CMAKE_PREFIX_PATH /Users/username/Downloads/libtorch)
find_package(Torch REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
# Setup Torch
add_executable(BLOCK_READER main.cpp)
target_include_directories(BLOCK_READER PRIVATE /src)
set_property(TARGET BLOCK_READER PROPERTY CXX_STANDARD 14)
target_link_libraries(BLOCK_READER "${TORCH_LIBRARIES}")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在M3 MacBook(Sonoma)上,并在关注。当我注意到此示例命令中的链接
指向
libtorch
的Linux分布时,我最终解决了此问题,这会使CMAKE混淆并导致其添加Linux Linker选项。我去Pytorch下载网站后,这个问题消失了: https://pytorch.org/cppdocs/cppdocs/installing 。ARM64
版本)。I'm on an M3 MacBook (Sonoma) and encountered the same problem when following through the tutorial in https://pytorch.org/cppdocs/installing.html . I eventually solved this problem when I noticed that the link in this example command
points to a Linux distribution of
libtorch
, which confuses CMake and causing it to add Linux linker options. This problem went away after I went to the PyTorch download site: https://pytorch.org/cppdocs/installing.html and downloaded the version oflibtorch
that corresponds to the correct system and the correct architecture for my system (since you're on M1, you probably want thearm64
version as well).