clang multiarch doens't work with precompiled headers

So I found out clang can do multiarch compiles (-arch arm64 -arch x86_64). But Apple seems to have left precompiled header support out. So I built the pch separately for each arch. That all works.

The next problem is that one needs to specify -include-pch foo.x64.pch and -include-pch foo.arm64.pch on the command line. This doesn't work on the compile line, since it tries to prepend arm64 AST to a x64 .o file, and vice versa.

So there is -Xarch_arm64 <arg> and -Xarch_x86_64 <arg>. But that option is limited to one argument. But "-include-pch foo.x64.pch" is two arguments.

More details of failed attempts here: https://github.com/llvm/llvm-project/issues/114626

And no splitting out the builds isn't the same, because then -valid_arch I don't think skips the other build. This are all libraries being built by Make, and then the universal app built using an Xcode project from the libraries.

You're dealing with a complex issue involving multi-architecture compilation in Clang, particularly with precompiled headers (PCH). The challenge arises from the need to specify different PCH files for different architectures while using the -Xarch flags, which only accept a single argument.

Use Separate Build Commands

One straightforward approach is to separate the build commands for each architecture. This means invoking the compiler twice, once for each architecture, specifying the appropriate PCH file each time.


# For x86_64

clang -arch x86_64 -include-pch foo.x64.pch -o output_x86.o source.c


# For arm64

clang -arch arm64 -include-pch foo.arm64.pch -o output_arm.o source.c

As I stated already, that doesn’t work with setting valid arch to one platform. So really need multi arch to work.

Now you also have 2 .o files, so then two libs, and then two more exe that have to be lipo-ed together. And now 2 targets. So it’s a bad cascade.

clang multiarch doens't work with precompiled headers
 
 
Q