简体   繁体   中英

Cannot link library for macOS-arm64 with executable for macOS-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?

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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