无法将 macOS-arm64 的库与 macOS-arm64 的可执行文件链接
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是由于您的系统中安装了不兼容版本的
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 symlinkingllvm-ar
overar
, or using the systemar
.在更改链接库的方式后,我设法编译了可执行文件。我的 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.