Facing similar issue while building ObjC static libraries.
- Sources
- VPNKit
- VPNKitAdapter (depends on VPNKit)
Here is Package file
let package = Package(
name: "VPNKit",
platforms: [
.iOS(.v14),
.macOS(.v10_15)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "VPNKit",
type:.static,
targets: ["VPNKit"]),
.library(
name: "VPNKitAdapter",
type:.static,
targets: ["VPNKitAdapter"])
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/CocoaLumberjack/CocoaLumberjack.git", from: "3.8.0")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "VPNKit",
dependencies: [
.product(name: "CocoaLumberjack", package: "CocoaLumberjack"),
.product(name: "CocoaLumberjackSwift", package: "CocoaLumberjack")
],
path: "Sources/VPNKit",
exclude: [
"Info.plist",
"../../fastlane",
"../../.gitmodules",
"../../DemoProject",
"../../Cartfile",
"../../Gemfile",
"../../.gitlab-ci.yml",
"SwiftSources"
],
cSettings: {
var settings: [CSetting] = [
.define("GCC_PREFIX_HEADER", to: "PrefixHeader.pch", nil)
]
settings.append(contentsOf: projectVPNKitcHeaderSearchPaths)
return settings
}(),
linkerSettings: [
.linkedFramework("Foundation"),
.linkedFramework("Security"),
.linkedFramework("CoreData"),
.linkedFramework("SystemConfiguration", .when(platforms: [.iOS, .macOS])),
.linkedFramework("ServiceManagement", .when(platforms: [.macOS])),
.linkedFramework("Cocoa", .when(platforms: [.macOS]))
]),
.testTarget(
name: "VPNKitTests",
dependencies: ["VPNKit"],
path: "Tests/VPNKitTests"
),
.target(
name: "VPNKitAdapter",
dependencies: [
.target(name: "VPNKit")
],
path: "Sources/VPNKitAdapter",
exclude: [
"Info.plist",
"../../fastlane",
"../../.gitmodules",
"../../DemoProject",
"../../Cartfile",
"../../Gemfile",
"../../.gitlab-ci.yml",
"SwiftSources"
],
sources: [
"Models"
],
resources: [
.copy("Resources/VPNCommon.xcdatamodeld"),
.copy("Resources/Version5to6.xcmappingmodel")
],
cSettings: {
var settings: [CSetting] = [
.define("GCC_PREFIX_HEADER", to: "VPNKitAdapter_PrefixHeader.pch", nil)
]
settings.append(contentsOf: projectVPNKitAdaptercHeaderSearchPaths)
return settings
}(),
linkerSettings: [
.linkedFramework("Foundation"),
.linkedFramework("Security"),
.linkedFramework("SystemConfiguration", .when(platforms: [.iOS, .macOS])),
.linkedFramework("ServiceManagement", .when(platforms: [.macOS])),
.linkedFramework("Cocoa", .when(platforms: [.macOS])),
.linkedFramework("CoreData", .when(platforms: [.iOS, .macOS]))
]),
.testTarget(
name: "VPNKitAdapterTests",
dependencies: ["VPNKitAdapter"],
path: "Tests/VPNKitAdapterTests"
)
]
)
Below issue Im facing, Added local package at VPNKitPackageTest Xcode sample project
and testing both libraries API at VPNKitTestingAPIs.swift class.
V3APIAdapter.h is public class from VPNKitAdapter library which has @import VPNKit; statement.
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_V3APIAdapter", referenced from:
objc-class-ref in VPNKitTestingAPIs.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Please help me to resolve it