[swift-users] How to create custom module without the package manager?

Bee bee.ography at gmail.com
Sat Dec 12 09:05:02 CST 2015


Sorry… I answer my own question. It need -l<module-name> argument. So, the
last command should be:

$ swiftc test.swift -lgreet

then it emitted a runnable app. I wonder why does it need an explicit
module name in the command line? While there is already an import clause
within the source file. Anyway, problem solved.

Thank you. :)


On Sat, Dec 12, 2015 at 9:53 PM, Bee <bee.ography at gmail.com> wrote:

> Sorry… forgot to say. I'm using Swift v.2.2 on Linux Ubuntu 14.04.
>
>
> On Sat, Dec 12, 2015 at 9:50 PM, Bee <bee.ography at gmail.com> wrote:
>
>> Hi all,
>>
>> I'd like to create my own simple custom module, but I don't want to use
>> the complicated package manager. Package manager is overkill for a simple
>> single source file module. So, here's what I've tried.
>>
>> file: greet.swift
>>
>> public func askName() {
>> print("What's your name? ")
>> let name = readLine()!
>> print("Hello, \(name)... good to see you!")
>> }
>>
>> file: main.swift
>>
>> askName()
>>
>> terminal:
>>
>> $ swiftc -emit-library -emit-object greet.swift -module-name greet
>>
>> emits greet.o
>>
>> $ ar rcs libgreet.a greet.o
>>
>> emits libgreet.a
>>
>> $ swiftc -emit-module greet.swift -module-name greet
>>
>> emits greet.swiftmodule and greet.swiftdoc
>>
>> All went well, so I think now I already have had the "greet" module.
>> Let's try to use it…
>>
>> file: test.swift
>>
>> import greet
>> askName()
>>
>> terminal:
>>
>> $ swiftc test.swift
>> clang: warning: argument unused during compilation: '-F/home/username'
>> /tmp/test-b63aab.o: In function `main':
>> /tmp/test-b63aab.o:(.text+0x41): undefined reference to
>> `_TF5greet7askNameFT_T_'
>> clang: error: linker command failed with exit code 1 (use -v to see
>> invocation)
>> <unknown>:0: error: link command failed with exit code 1 (use -v to see
>> invocation)
>>
>> What's happening? What's wrong? How can I fix it?
>>
>> Thank you.
>>
>> Regards,
>>
>> --
>> -Bee-
>>
>>
>
>
> --
> -Bee-
>
>


-- 
-Bee-
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20151212/2c2d9d27/attachment.html>


More information about the swift-users mailing list