在Mac上的约会Linker LD

发布于 2025-01-26 21:03:29 字数 1413 浏览 3 评论 0 原文

我正在尝试使用指令来编译一个示例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}")

I am trying to compile an example pytroch c++ project using instructions at:

https://pytorch.org/cppdocs/installing.html

When i reach the point of calling:

cmake -DCMAKE_PREFIX_PATH=/absolute/path/to/libtorch ..
cmake --build . --config Release

I get an error:

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

It looks like the issue is that the linker doesnt understand the option --no-as-needed.

After some research it looks like newer version of the linker support this option, but not the version i have.

So my question is how do i update my linker to a version that support this option?

I am on a Apple M1 (BigSur)..

It is my understanding that ld is part of gcc so can i just update gcc?

Btw here is my 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

新一帅帅 2025-02-02 21:03:29

我在M3 MacBook(Sonoma)上,并在关注。当我注意到此示例命令中的链接

wget https://download.pytorch.org/libtorch/nightly/cpu/libtorch-shared-with-deps-latest.zip

指向 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

wget https://download.pytorch.org/libtorch/nightly/cpu/libtorch-shared-with-deps-latest.zip

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 of libtorch that corresponds to the correct system and the correct architecture for my system (since you're on M1, you probably want the arm64 version as well).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文