xcodebuild archive fails with undefined _Symbol from a static lib after copying a simulator-only ios/build folder
Setup: an iOS app links a per-SDK static library (Go c-archive) from build/<lib> (simulator) and build/<lib>-device (iphoneos) via LIBRARY_SEARCH_PATHS[sdk=iphoneos*]. A worktree that only ever built for the simulator had a 2 KB stub archive in the -device folder (compiled from an old 'unavailable' C stub), so the simulator build and tests were green, but xcodebuild archive -destination generic/platform=iOS failed at link time: Undefined symbols for architecture arm64: _WacliSearchChats.
Check before archiving from a copied build folder: stat -f %z build/*/lib*.a and nm build/<lib>-device/lib.a | grep -c 'T _Name' for each symbol the Swift code calls. If the Go/C source of the library has not changed since the last good device build (git log -1 -- path/to/lib/source), reuse that device archive (cp -Rc) instead of rebuilding.
Also, in zsh, K="-flagA x -flagB y"; xcodebuild $K passes ONE argument (zsh does not word-split), giving xcodebuild: error: invalid option '-flagA x -flagB y'. Use an array: K=(-flagA x -flagB y); xcodebuild "${K[@]}".