无法将 macOS-arm64 的库与 macOS-arm64 的可执行文件链接

发布于 2025-01-10 12:03:24 字数 683 浏览 0 评论 0原文


I have some trouble with creating a build system on a **Monterey M1 MacBook**:

到目前为止,我有一个可用的 Makefile 来构建和链接库。
(简化:g++ -c 将所有 .cpp 文件转换为 .o 文件 → ar -r <.o 文件> libmyLibrary.a>
效果很好

问题:
当我尝试构建使用所述 libmyLibrary.a 的可执行二进制文件时。源文件的编译工作正常,但我收到以下(看似无意义的)链接器警告:

ld: warning: ignoring file /Path/to/lib/libmyLibrary.a,
building for macOS-arm64 but attempting to link with file built for macOS-arm64

→ I ofc then get some Undefined Symbols for Architecture arm64: ...;引用自:<来自可执行文件的内容>

为与库相同的目标进行构建怎么会成为问题?

I have some trouble with creating a build system on a **Monterey M1 MacBook**:

So far I have a working Makefile to build and link a library.
(simplified: g++ -c all .cpp files into .o files → ar -r <.o files> libmyLibrary.a>

works great

THE PROBLEM:
When I try to build an executable binary that uses said libmyLibrary.a. The compilation of source files works fine, but I get the following (seemingly nonsensical) linker warning:

ld: warning: ignoring file /Path/to/lib/libmyLibrary.a,
building for macOS-arm64 but attempting to link with file built for macOS-arm64

→ I ofc then get some Undefined symbols for architecture arm64: ... <stuff from library> referenced from: <stuff from executable>

How can building for the same target as the library be a problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

胡大本事 2025-01-17 12:03:24

这是由于您的系统中安装了不兼容版本的 ar 造成的。自制 binutils 中的 ar 似乎已损坏。这可以通过在 ar 上符号链接 llvm-ar 或使用系统 ar 来解决。

This is caused by having an incompatible version of ar installed in your system. ar in homebrew binutils seems to be broken. This can be resolved by symlinking llvm-ar over ar, or using the system ar.

ヤ经典坏疍 2025-01-17 12:03:24

在更改链接库的方式后,我设法编译了可执行文件。我的 Makefile 还链接了一个预编译头 .pch 文件。

删除后,效果很好。

I managed to compile the executable after changing how I link my library. My Makefile also linked a precompiled header .pch file.

After removing that, it worked fine.

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