Linux上的OS X上的Swift编译? [英] Swift on OS X compiling for Linux?

查看:103
本文介绍了Linux上的OS X上的Swift编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对其他平台上Swift的构建过程感到困惑.

I'm confused by the build process for Swift on other platforms.

Swift是否允许我在OS X上构建Linux项目,还是我需要专门在Linux上使用Swift来构建我打算在其中使用的任何东西?

Does Swift allow me to build a Linux project on OS X, or do I need to use Swift specifically on Linux to to build anything I plan on using there?

我查看了文档,但是这个主题尚不清楚. ..

I looked at the documentation, but it's not really clear on this topic...

推荐答案

现在可以为iOS,OS X和Linux编译不导入任何框架的纯Swift应用程序.

A pure Swift application which is not importing any framework can now be compiled for iOS, OS X and for Linux.

您将生成不同的可执行文件,因为它是不同的平台,但是代码源可以相同,只需要针对各自的平台进行编译即可.

You will generate different executables, because it's different platforms, but the code source can be the same, it just has to be compiled for the respective platform.

区别在于导入框架的时间.

如果您导入UIKit来制作iOS应用程序,显然您将无法在Linux上进行编译,因为Linux没有这些iOS UIKit库,因此只能在Mac上通过Xcode使用.

If you import UIKit to make an iOS application, obviously you won't be able to compile this on Linux, because Linux doesn't have those iOS UIKit libraries, they're only available on a Mac via Xcode.

如果您导入Cocoa来制作OS X应用程序,则采用相同的逻辑,它仅适用于OS X.

If you import Cocoa to make an OS X application, the same logic applies, it works only for OS X.

以同样的方式,如果导入特定的Linux库(例如Glibc),而不能在Mac上运行,则可以制作仅在Linux上可用的Swift代码.

The same way, you can make Swift code that only works on Linux if you import specific Linux libraries, like Glibc, that won't work on the Mac.

等等,

您需要记住的是,在为平台制作应用程序时,编程语言并不重要,而是与您链接的框架和库具有决定性.

What you need to remember is that the programming language isn't that relevant when it comes to make applications for a platform, it's the frameworks and libraries that you're linked to that are decisive.

不同的Swift版本带有不同的编译器(实际上是不同的工具链),因此要直接回答,不,您不能使用普通的OS X Swift编译器为Linux Swift进行编译,必须使用Swift.org的版本.

Different Swift versions come with different compilers (different toolchains, actually) so to answer directly, no you can't compile for Linux Swift with the normal OS X Swift compiler, you have to use the Swift.org's one.

这篇关于Linux上的OS X上的Swift编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆