-
Notifications
You must be signed in to change notification settings - Fork 749
Description
Summary
Undefined Symbols for Architecture arm64 When Using ApolloGenerated Files in a Test Target with SPM
Description
I am encountering a linker error when attempting to use Apollo-generated files in a test target within a Swift Package Manager (SPM) project.
Environment
- Apollo iOS Version: 1.18.0
- Project Type: SPM (Swift Package Manager)
- Xcode Version: 16.0 (16A242d)
- macOS Version: 15.3.1 (24D70)
Issue
When Apollo-generated files are added to a target, the target builds successfully. However, when these same files are included in a test target, the test target fails to build with the following error:
Undefined symbols for architecture arm64: “ModuleTarget.ApolloNetwork.__allocating_init() -> ModuleTarget.ApolloNetwork”, referenced from: ModuleTarget_UnitTests.ApolloNetworkTests.setUp() -> () in AllFiles_Tests.o “type metadata accessor for ModuleTarget.ApolloNetwork”, referenced from: ModuleTarget_UnitTests.ApolloNetworkTests.setUp() -> () in AllFiles_Tests.o “nominal type descriptor for ModuleTarget.ApolloNetwork”, referenced from: _symbolic _____Sg 12ModuleTarget13ApolloNetworkC in AllFiles_Tests.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
Findings
- When the Apollo-generated files are manually added to an Xcode project (instead of using SPM), both variations work correctly.
- However, when using Swift Package Manager, the test target is unable to link the Apollo-generated files properly, leading to undefined symbol errors.
Expected Behavior
The test target should be able to correctly link against Apollo-generated files when using Swift Package Manager, just as it does when the files are manually added to an Xcode project.
Version
1.18.0
Steps to reproduce the behavior
Reproduction Steps
I have tested two different configurations, and both exhibit the same issue in the test target:
Variation 1: SPM Without Binary
- In this variation, the Apollo-generated files are linked as a target within the Swift package.
- This target is then added as a dependency to the test target.
- The following is the complete configuration of the SPM project:
import PackageDescription
// MARK: Source Targets
let ModuleTarget: Target =
.target(
name: “ModuleTarget”,
dependencies: [
.product(name: “Apollo”, package: “sources.apollo-ios”),
.product(name: “ApolloAPI”, package: “sources.apollo-ios”),
“ApolloSchema”
],
path: “Module/Sources”,
resources: [ ]
)
let ApolloSchema: Target =
.target(
name: “ApolloSchema”,
dependencies: [
.product(name: “Apollo”, package: “sources.apollo-ios”),
.product(name: “ApolloAPI”, package: “sources.apollo-ios”),
],
path: “DataModel/ApolloGenerated”,
resources: [ ]
)
let sourceTargets = [ModuleTarget, ApolloSchema]
// MARK: - Test Targets
let ModuleTarget_UnitTests: Target =
.testTarget(
name: “ModuleTarget_UnitTests”,
dependencies: [
.product(name: “Apollo”, package: “sources.apollo-ios”),
.product(name: “ApolloAPI”, package: “sources.apollo-ios”),
“ApolloSchema”,
],
path: “Module/Tests”
)
let testTargets = [ModuleTarget_UnitTests]
// MARK: - Package Definition
let package = Package(
name: “SPM_Without_Binary”,
defaultLocalization: “en”,
platforms: [
.iOS(.v17)
],
products: [
.library(name: “ModuleTarget”, targets: [“ModuleTarget”, “ApolloSchema”]),
.library(name: “ModuleTarget_UnitTests”, targets: [“ModuleTarget_UnitTests”, “ModuleTarget”, “ApolloSchema”])
// .library(name: “ModuleTarget”, type: .static, targets: [“ModuleTarget”, “ApolloSchema”])
],
dependencies: [
.package(name: “sources.apollo-ios”, url: “https://github.com/apollographql/apollo-ios.git”, from:“1.18.0”),
],
targets: sourceTargets + testTargets
)Variation 2: SPM With Binary
- In this variation, the Apollo-generated files are linked as a binary target.
- This binary target is then added as a dependency to the test target.
- The following is the complete configuration of the SPM project:
import PackageDescription
// MARK: Source Targets
let ModuleTarget: Target =
.target(
name: “ModuleTarget”,
dependencies: [
.product(name: “Apollo”, package: “sources.apollo-ios”),
.product(name: “ApolloAPI”, package: “sources.apollo-ios”),
“ApolloSchemaBinary”
],
path: “Module/Sources”,
resources: [ ]
)
let ApolloSchema: Target =
.binaryTarget(
name: “ApolloSchemaBinary”,
path: “ApolloSchema/Binary/ApolloSchema.xcframework”
)
let sourceTargets = [ModuleTarget, ApolloSchema]
// MARK: - Test Targets
let ModuleTarget_UnitTests: Target =
.testTarget(
name: “ModuleTarget_UnitTests”,
dependencies: [
.product(name: “Apollo”, package: “sources.apollo-ios”),
.product(name: “ApolloAPI”, package: “sources.apollo-ios”),
.product(name: “ApolloTestSupport”, package: “sources.apollo-ios”),
“ApolloSchemaBinary”,
],
path: “Module/Tests”
)
let testTargets = [ModuleTarget_UnitTests]
// MARK: - Package Definition
let package = Package(
name: “SPM_With_Binary”,
defaultLocalization: “en”,
platforms: [
.iOS(.v17)
],
products: [
.library(name: “ModuleTarget”, targets: [“ModuleTarget”, “ApolloSchemaBinary”])
],
dependencies: [
.package(name: “sources.apollo-ios”, url: “https://github.com/apollographql/apollo-ios.git”, from:“1.18.0”),
],
targets: sourceTargets + testTargets
)Logs
Ld /Users/avasudev/Library/Developer/Xcode/DerivedData/SPM_Without_Binary-czxxncravpupvaakyrfgavzfxkmd/Build/Products/Debug-iphonesimulator/ModuleTarget_UnitTests.xctest/ModuleTarget_UnitTests normal (in target ‘ModuleTarget_UnitTests’ from project ‘SPM_Without_Binary’)
cd /Users/avasudev/Desktop/ABHI/iOS-Apps/ApolloPOC/Apollo\ Binary\ with\ Test\ Target\ POC/SPM_Without_Binary
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -Xlinker -reproducible -target arm64-apple-ios17.0-simulator -bundle -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.0.sdk -O0 -L/Users/avasudev/Library/Developer/Xcode/DerivedData/SPM_Without_Binary-czxxncravpupvaakyrfgavzfxkmd/Build/Intermediates.noindex/EagerLinkingTBDs/Debug-iphonesimulator -L/Users/avasudev/Library/Developer/Xcode/DerivedData/SPM_Without_Binary-czxxncravpupvaakyrfgavzfxkmd/Build/Products/Debug-iphonesimulator -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/lib -F/Users/avasudev/Library/Developer/Xcode/DerivedData/SPM_Without_Binary-czxxncravpupvaakyrfgavzfxkmd/Build/Intermediates.noindex/EagerLinkingTBDs/Debug-iphonesimulator -F/Users/avasudev/Library/Developer/Xcode/DerivedData/SPM_Without_Binary-czxxncravpupvaakyrfgavzfxkmd/Build/Products/Debug-iphonesimulator/PackageFrameworks -F/Users/avasudev/Library/Developer/Xcode/DerivedData/SPM_Without_Binary-czxxncravpupvaakyrfgavzfxkmd/Build/Products/Debug-iphonesimulator/PackageFrameworks -F/Users/avasudev/Library/Developer/Xcode/DerivedData/SPM_Without_Binary-czxxncravpupvaakyrfgavzfxkmd/Build/Products/Debug-iphonesimulator/PackageFrameworks -F/Users/avasudev/Library/Developer/Xcode/DerivedData/SPM_Without_Binary-czxxncravpupvaakyrfgavzfxkmd/Build/Products/Debug-iphonesimulator -iframework /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks -iframework /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.0.sdk/Developer/Library/Frameworks -filelist /Users/avasudev/Library/Developer/Xcode/DerivedData/SPM_Without_Binary-czxxncravpupvaakyrfgavzfxkmd/Build/Intermediates.noindex/SPM_Without_Binary.build/Debug-iphonesimulator/ModuleTarget_UnitTests.build/Objects-normal/arm64/ModuleTarget_UnitTests.LinkFileList -Xlinker -rpath -Xlinker /Users/avasudev/Library/Developer/Xcode/DerivedData/SPM_Without_Binary-czxxncravpupvaakyrfgavzfxkmd/Build/Products/Debug-iphonesimulator/PackageFrameworks -Xlinker -rpath -Xlinker @loader_path/Frameworks -Xlinker -rpath -Xlinker @loader_path/../Frameworks -dead_strip -Xlinker -object_path_lto -Xlinker /Users/avasudev/Library/Developer/Xcode/DerivedData/SPM_Without_Binary-czxxncravpupvaakyrfgavzfxkmd/Build/Intermediates.noindex/SPM_Without_Binary.build/Debug-iphonesimulator/ModuleTarget_UnitTests.build/Objects-normal/arm64/ModuleTarget_UnitTests_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -Xlinker -debug_variant -fobjc-link-runtime -fprofile-instr-generate -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -L/usr/lib/swift -Xlinker -add_ast_path -Xlinker /Users/avasudev/Library/Developer/Xcode/DerivedData/SPM_Without_Binary-czxxncravpupvaakyrfgavzfxkmd/Build/Intermediates.noindex/SPM_Without_Binary.build/Debug-iphonesimulator/ModuleTarget_UnitTests.build/Objects-normal/arm64/ModuleTarget_UnitTests.swiftmodule -Wl,-no_warn_duplicate_libraries -Wl,-no_warn_duplicate_libraries -Wl,-no_warn_duplicate_libraries -framework XCTest -lXCTestSwiftSupport -Xlinker -no_adhoc_codesign -Xlinker -dependency_info -Xlinker /Users/avasudev/Library/Developer/Xcode/DerivedData/SPM_Without_Binary-czxxncravpupvaakyrfgavzfxkmd/Build/Intermediates.noindex/SPM_Without_Binary.build/Debug-iphonesimulator/ModuleTarget_UnitTests.build/Objects-normal/arm64/ModuleTarget_UnitTests_dependency_info.dat -o /Users/avasudev/Library/Developer/Xcode/DerivedData/SPM_Without_Binary-czxxncravpupvaakyrfgavzfxkmd/Build/Products/Debug-iphonesimulator/ModuleTarget_UnitTests.xctest/ModuleTarget_UnitTests -Xlinker -add_ast_path -Xlinker /Users/avasudev/Library/Developer/Xcode/DerivedData/SPM_Without_Binary-czxxncravpupvaakyrfgavzfxkmd/Build/Intermediates.noindex/Apollo.build/Debug-iphonesimulator/Apollo.build/Objects-normal/arm64/Apollo.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/avasudev/Library/Developer/Xcode/DerivedData/SPM_Without_Binary-czxxncravpupvaakyrfgavzfxkmd/Build/Intermediates.noindex/Apollo.build/Debug-iphonesimulator/ApolloAPI.build/Objects-normal/arm64/ApolloAPI.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/avasudev/Library/Developer/Xcode/DerivedData/SPM_Without_Binary-czxxncravpupvaakyrfgavzfxkmd/Build/Intermediates.noindex/SPM_Without_Binary.build/Debug-iphonesimulator/ApolloSchema.build/Objects-normal/arm64/ApolloSchema.swiftmodule
ld: warning: Could not parse or use implicit file ‘/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks/SwiftUICore.framework/SwiftUICore.tbd’: cannot link directly with ‘SwiftUICore’ because product being built is not an allowed client of it
Undefined symbols for architecture arm64:
“ModuleTarget.ApolloNetwork.__allocating_init() -> ModuleTarget.ApolloNetwork”, referenced from:
ModuleTarget_UnitTests.ApolloNetworkTests.setUp() -> () in AllFiles_Tests.o
“type metadata accessor for ModuleTarget.ApolloNetwork”, referenced from:
ModuleTarget_UnitTests.ApolloNetworkTests.setUp() -> () in AllFiles_Tests.o
“nominal type descriptor for ModuleTarget.ApolloNetwork”, referenced from:
_symbolic _____Sg 12ModuleTarget13ApolloNetworkC in AllFiles_Tests.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)Anything else?
Additional Information - Sample Project
I have attached a .zip folder containing the sample projects directly to this issue. I hope this helps.