Skip to content

Instantly share code, notes, and snippets.

@dabrahams
Last active May 18, 2021 00:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dabrahams/c7de10507e98463e71bf8b4586f5e51a to your computer and use it in GitHub Desktop.
Save dabrahams/c7de10507e98463e71bf8b4586f5e51a to your computer and use it in GitHub Desktop.
Linking and importing a swift module for use in the REPL
$ echo 'public func f() { print("YES") }' > x.swift
$ swiftc -emit-library -emit-module -module-link-name x  x.swift
$ swift -L . -I .
Welcome to Apple Swift version 5.4 (swiftlang-1205.0.26.9 clang-1205.0.19.55).
Type :help for assistance.
  1> import x
import x
  2> f()
f()
YES
@Frizlab
Copy link

Frizlab commented May 13, 2021

I get

error: Couldn't lookup symbols:
  x.f() -> ()

with Swift version

Apple Swift version 5.4 (swiftlang-1205.0.26.9 clang-1205.0.19.55)
Target: arm64-apple-darwin20.4.0

😕

@Frizlab
Copy link

Frizlab commented May 13, 2021

It works if I add -L. when launching the REPL though.

@dabrahams
Copy link
Author

Thanks, updated the Gist for use with stock Swift.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment