Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
168 views
in Technique[技术] by (71.8m points)

Swift makefile with swiftc

I am trying to create a simple makefile to compile swift code. Here is my Makefile:

NAME        = computor

DIRS        = ComputorV1/

LIST        =   Parser.swift    
            main.swift

SOURCE      = $(addprefix $(DIRS), $(LIST))
OBJ     = $(patsubst %.swift,%.o,$(SOURCE))

all:
    @make $(NAME)

%.o: %.swift
    @swiftc -c $< -o $@

$(NAME): $(OBJ)
    @swiftc $(OBJ) -o $(NAME)

clean:
    @rm -f $(OBJ)

fclean: clean
    @rm -f $(NAME)

re: fclean all

.PHONY: all clean fclean re debug test

But when I am trying to make it, I always get an error

"ComputorV1/main.swift:10:14: error: cannot find 'Parser' in scope let parser = Parser()"

main.swift and Parser.swift code are simply

import Foundation

let parser = Parser()

and

final class Parser {

    init() {
        print("privet")
    }
}

Where I did wrong? Maybe there is a some flag option for swiftc to ling one *.swift file with another, but I can't find that

question from:https://stackoverflow.com/questions/65935672/swift-makefile-with-swiftc

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Makefile generates a sequence of commands that you can show by using make clean; make --dry-run. This sequence of commands will be easily recognized by Swift specialists.

In order to debug the problem, you may compare output of make --dry-run with results of running these commands by hand. Or alter Makefile to get a similar result.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...