Compiling my own module via the command line


Let's say I've got two files:


public func vogel() {

and VogelScript.swift

import VogelModule


Now I'm making my module:
swiftc -emit-library -emit-module -parse-as-library VogelModule.swift

And I get VogelModule.swiftdoc, VogelModule.swiftmodule, and libVogelModule.dylib. Nice!

But now I want to use it:
swiftc VogelScript.swift

Doesn't work of course, since "VogelModule" is unknown. Next try:
swiftc VogelScript.swift -I .

That won't complain about the missing module, but it still can't link it. So, next try:
swiftc VogelScript.swift -I . -L .

But it seems like it can't find the libVogelModule.dylib, which is strange. Using -l doesn't seem to work either.

What am I doing wrong?

Best regards, V.

What are you passing when you pass -l. Using your example these steps work for me:

swiftc -emit-library -emit-module -parse-as-library VogelModule.swift
swiftc VogelScript.swift -I . -L . -lVogelModule

Swift has support for "autolinking", automatically matching a dylib up with an imported module, but it doesn't do that for libraries you build by default. It'll do it for frameworks (which have a known directory layout), or if you use the -module-link-name <foo> option when you build the library.

Thank you guys for your help. I resolved this, turns out -l is indeed the solution.

What I didn't know was that it's not this:
swiftc VogelScript.swift -I . -L . -l VogelModule
But this:
swiftc VogelScript.swift -I . -L . -lVogelModule

So, -l doesn't accept spaces, unlike lots of other options. I'm unaware of the reasons why, but that's how it works.