The last couple of days I've been getting undefined symbol
errors.
I'm creating a package that's an executable. I created it through the cli
swift package init --type executable
It's a Vapor console application. I've got the following structure:
- Sources
- Vii
- ViiLibrary
- Tests
- ViiTests
- ViiTests.swift
I'm basically using my ViiLibrary
as a target that can be tested as according to this answer you can't test an executable.
Inside my Vii
directory I am importing the ViiLibrary
but when I try to access anything in that Library I get symbol errors.
Undefined symbols for architecture x86_64:
"ViiLibrary.ViiDatabaseType.init(input: Swift.String) -> ViiLibrary.ViiDatabaseType", referenced from:
Vii.ViiCommand.run(using: ConsoleKit.CommandContext, signature: Vii.ViiCommand.Signature) throws -> () in Vii.o
"ViiLibrary.Credentials.init(port: Swift.Int, host: Swift.String, username: Swift.String, password: Swift.String, database: Swift.String) -> ViiLibrary.Credentials", referenced from:
Vii.ViiCommand.run(using: ConsoleKit.CommandContext, signature: Vii.ViiCommand.Signature) throws -> () in Vii.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
And I really don't know why or how to fix these? I am importing the same ViiLibrary
into my Tests via @testable import ViiLibrary
and they are able to run fine when being tested. But not if they are inside my Vii
target.
I've cleaned the build, wiped the derived data and restarted XCode a few times, but it doesn't seem to resolve the problem.
For completeness, here is the Credentials
struct. I have declared all the types, properties and initializes on both library types as public
public struct Credentials {
public let port: Int
public let host: String
public let username: String
public let password: String
public let database: String
public init(port: Int, host: String, username: String, password: String, database: String){
self.port = port
self.host = host
self.username = username
self.password = password
self.database = database
}
}