swiftc -target和-target-cpu选项有哪些可用的目标?

Zap*_*nuk 18 swift swift3

这个问题是关于交叉编译的.

使用swift编译器的-target-target-cpu选项可以使用哪种不同的目标?我在哪里可以找到概述?

它只是在那里创建iOS/watchOS应用程序,还是我可以用它来在macOS上创建linux程序(常规x86-64处理器)?

我尝试搜索github存储库,发现'x86_64-unknown-linux-gnu'作为目标.但是,当我尝试编译一个简单的"hello world"程序(swiftc -target x86_64-unknown-linux-gnu test.swift)时,我收到此错误:

<unknown>:0: error: unable to load standard library for target 'x86_64-unknown-linux-gnu'
Run Code Online (Sandbox Code Playgroud)

编辑: 我同意CristiFati.这个问题的最后一部分是关于如何正确地包含/引用glibc(?!?).

Far*_*had 12

如果你看一下在Github上斯威夫特库(精确位置:swift/utils/swift_build_support/swift_build_support/targets.py)你会看到所有的主机目标的线149-192target.py.

支持:

def host_target():
    """
    Return the host target for the build machine, if it is one of
    the recognized targets. Otherwise, throw a NotImplementedError.
    """
    system = platform.system()
    machine = platform.machine()

    if system == 'Linux':
        if machine == 'x86_64':
            return StdlibDeploymentTarget.Linux.x86_64
        elif machine.startswith('armv7'):
            # linux-armv7* is canonicalized to 'linux-armv7'
            return StdlibDeploymentTarget.Linux.armv7
        elif machine.startswith('armv6'):
            # linux-armv6* is canonicalized to 'linux-armv6'
            return StdlibDeploymentTarget.Linux.armv6
        elif machine == 'aarch64':
            return StdlibDeploymentTarget.Linux.aarch64
        elif machine == 'ppc64':
            return StdlibDeploymentTarget.Linux.powerpc64
        elif machine == 'ppc64le':
            return StdlibDeploymentTarget.Linux.powerpc64le
        elif machine == 's390x':
            return StdlibDeploymentTarget.Linux.s390x

    elif system == 'Darwin':
        if machine == 'x86_64':
            return StdlibDeploymentTarget.OSX.x86_64

    elif system == 'FreeBSD':
        if machine == 'amd64':
            return StdlibDeploymentTarget.FreeBSD.x86_64

    elif system == 'CYGWIN_NT-10.0':
        if machine == 'x86_64':
            return StdlibDeploymentTarget.Cygwin.x86_64

    elif system == 'Windows':
        if machine == "AMD64":
            return StdlibDeploymentTarget.Windows.x86_64

    raise NotImplementedError('System "%s" with architecture "%s" is not '
                              'supported' % (system, machine))
Run Code Online (Sandbox Code Playgroud)

  • 这是很好的信息.谢谢.你能添加这些东西导致的实际(文本)值吗?否则答案感觉不完整. (2认同)