Building universal C++ libraries from source

My app uses several 3rd party C++ libraries such as Google's Protobuf and many others.

Most of them are dynamic libs (.dylib) and were built using standard .configure/make/make install from source.

It is not clear to me how to build these in order to get universal libraries which run on Intel and Apple Silicon.

Is there a flag in the standard build system that causes it to output a universal binary? Or can I build two libs (one for Intel and one for Apple Silicon) and combine them into a universal binary?
In most basic ./configure scripts, you could try adding CFLAGS to build for both architectures simultaneously:
CFLAGS="-arch x86_64 -arch arm64"

or, if you (need/want to) build for both architectures independently, you can afterwards use the lipo command-line tool to combine both binaries into a single Universal Binary.

The Port Your Mac App to Apple Silicon WWDC session goes over more build scenarios:
https://developer.apple.com/wwdc20/10214

using following to build protobuf 3.20 fat library, passing the make check

CXXFLAGS="-arch x86_64 -arch arm64 -mmacosx-version-min=11.0 -std=c++11"

Building universal C++ libraries from source
 
 
Q