"Undefined symbols for architecture x86_64" during linking

Hey! I would greatly appreciate your help with the following problem:

Folder structure:

Resources
	└──Toolchain
		└──swift-5.2.4-RELEASE.xctoolchain
	└──MyLibrary
		└──.build
		└──Package.swift
		└──Sources
			└──MyLibrary
				└──MyLibrary.swift
	└──Template
		└──main.swift
	└──Output

main.swift:

import MyLibrary
let book = Book()
print(book.text)

MyLibrary.swift:

public struct Book {
    public var text: String
    public init() {
        self.text = "Hello, World!"
    }
}

I am trying to build the main.swift file using the provided .xctoolchain using the following command:

Resources/Toolchain/swift-5.2.4-RELEASE.xctoolchain/usr/bin/swift --driver-mode=swiftc Resources/Template/main.swift -I Resources/MyLibrary/.build/debug/ -L Resources/MyLibrary/.build/debug/ -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -target x86_64-apple-macosx10.15 -o Resources/Output/

However I am getting the following error:

Undefined symbols for architecture x86_64:
  "_$s9MyLibrary4BookVACycfC", referenced from:
      _main in main-61b0d9.o
ld: symbol(s) not found for architecture x86_64
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)

Any help would be greatly appreciated!

Additional information:

  • MyLibrary was built using swift build --target MyLibrary